saravanan
saravanan

Reputation: 1675

How to implement Click event in QGraphicsWidget?

i used QT Example : appchooser . i plan to implement the Toolbar with that. i modified it's working fine.

i have problem to catch the click event. i tried but i didn't get the solution. please help me to fix the problem.

for clicking the item i need to call the ItemClicked() method

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

Please help to find the solution..

Upvotes: 3

Views: 1460

Answers (1)

RedX
RedX

Reputation: 15175

You must subclass it since virtual void grabMouseEvent ( QEvent * event ) (in fact all mouse events) is(are) protected and there are no signals for 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]

Upvotes: 2

Related Questions