How to implement Click event in QGraphicsWidget?

i using QT Example: appchooser. I plan to implement a toolbar with this. I changed his work fine.

I have a problem to catch a click event. I tried, but I did not get a solution. please help me solve the problem.

to click an item that should call a method ItemClicked()

project source code. http://www.4shared.com/file/Xutwi3DR/test4anime.html

Please help find a solution ..

+3
source share
1 answer

You must subclass it because virtual void grabMouseEvent ( QEvent * event )(in fact, all mouse events) are protected (and) and do not exist signalsfor click events for this widget.

class MyGraphicsWidget : public QGraphicsWidget{

Q_OBJECT

//Implement the constructors as you wish, if you need help with this check a Qt tutorial out.

  //to get the mouse events implement the needed functions
  //there are many others so just check the docs [1]
  virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ){
    //do whatever you need here. Emit SIGNALS, show menus, etc
  }
};

http://doc.qt.io/archives/qt-4.7/qgraphicswidget-members.html [1]

+2

Source: https://habr.com/ru/post/1781976/


All Articles