PDA

View Full Version : mouseDoubleClickEvent on QGraphicsItem's



been_1990
3rd August 2009, 12:13
How can I check for a double-click on my items?

yogeshgokul
3rd August 2009, 12:21
How can I check for a double-click on my items?
What items? :confused::confused:

wagmare
3rd August 2009, 12:29
bool QGraphicsItem::sceneEvent ( QEvent * event )

event is QEvent::GraphicsSceneMouseDoubleClick

been_1990
4th August 2009, 01:55
How exactly do I use that?

navi1084
4th August 2009, 05:00
why cant you re-impliment "void mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * event ) ".

To use sceneEvent(), u should first register the item for which u need all the events and filter the events.
To register you can use "void installSceneEventFilter ( QGraphicsItem * filterItem )".
and override bool sceneEvent ( QEvent * event ) and filter the events which you need..

been_1990
4th August 2009, 11:43
wow..... maybe an example? Thats a litle beyond me.

wagmare
4th August 2009, 14:40
see the previous to last post of this thread
http://www.qtcentre.org/forum/f-newbie-4/t-catch-pressed-keys-22921.html

been_1990
5th August 2009, 11:00
bool RecRepView:: eventFilter(QObject *ob, QEvent *e)
{
if(e->type() == QEvent::KeyPress){
printf("is it coming inside event..\n");
const QKeyEvent *ke = static_cast<QKeyEvent *>(e);
if(ke->key()==Qt::Key_F1){
qApp->quit();
printf("Logout buttin clicked..\n");
}
return true;
}
return QWidget::eventFilter(ob, e);
}

Ok. So just by having this function it gets called automatically every time QObject *ob receives an event?
Or do I still need signals/slots?

wagmare
5th August 2009, 11:08
e->type() == QEvent::KeyPress
instead u use

e->type() == QEvent::GraphicsSceneMouseDoubleClick

and inside the condition u can do any thing .. display a alert message dialog or emit a signal or return a statement ..etc ..

been_1990
6th August 2009, 11:12
so I'll use the function like ? :

eventFilter(myGraphicsItem, QEvent *e);

wagmare
6th August 2009, 11:26
so I'll use the function like ? :

eventFilter(myGraphicsItem, QEvent *e);

:confused: why u have to use function like eventFilter(myGraphicsItem, QEvent *e) ...!

its a virtual function reimplement the virtual function in your QGraphicsView class and install this event filter in your QGraphicsScene() of the view ..

see the link
http://doc.trolltech.com/4.3/eventsandfilters.html#event-filters

been_1990
7th August 2009, 02:52
Okay. Now my mind cleared up. Thanks for the help, my problem is solved.Tx.