[Qt-interest] QGraphicsProxyWidget, Disabled Widgets and Mouse Events

Karol Krizka kkrizka at gmail.com
Mon Dec 22 19:49:09 CET 2008


Hi there,

I am wondering if it is possible for a QGraphicsProxyWidget to accept click 
and hover events, even if the widget that it is a proxy for has been disabled. 

What I want to do is to use a scaled down QGraphicsProxyWidget as a button, 
which when clicked, zooms in and lets the user use the controls in the 
QGraphicsProxyWidget. Hover to make sure that the initial mouse click (that 
causes the zoom-in) is not interpreted by any of the controls in the widget, I 
would like to disable the widget itself.

I tried the following code and it did not work. Using "setEnabled(true)" made 
it work though..

#include <QGraphicsScene>
#include <QGraphicsView>
#include <QApplication>
#include <QGraphicsProxyWidget>
#include <QDebug>
#include <QPushButton>

class QGraphicsClickableItem : public QGraphicsProxyWidget
{
  public:
  QGraphicsClickableItem( QGraphicsItem * parent = 0 
):QGraphicsProxyWidget(parent) 
  {
    setAcceptHoverEvents(true);
  }

  void mousePressEvent( QGraphicsSceneMouseEvent *event )
  {
    qDebug() << "Click!";
  }

  void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
  {
    qDebug() << "Enter!";
  }
};


int main(int argc,char* argv[])
{
  QApplication app(argc,argv);

  QGraphicsScene scene;
  QGraphicsView view(&scene);

  QGraphicsClickableItem test;
  QPushButton b1;
  b1.setEnabled(false);
  test.setWidget(&b1);
  scene.addItem(&test);

  view.show();

  return app.exec();
}








--
Cheers,
Karol Krizka



More information about the Qt-interest-old mailing list