QLabel and some mouse click signals
-
wrote on 2 Jun 2011, 08:46 last edited by
Hi All,
I need catch some signal\event from QLabel, when user clicked by mouse at the label.
In Qt Assistant i find @protected: void mousePressEvent( QMouseEvent * e );@ but for use this code i need create new class inherited from QLabel, but i don't wish to do that. Maby some one know other variant? -
wrote on 2 Jun 2011, 09:00 last edited by
Install event filter on the label of interest and act accordingly in eventFilter() method. Make sure to return whether the event is consumed or not.
"About event filters ...":http://doc.qt.nokia.com/latest/eventsandfilters.html#event-filtershttp:
-
wrote on 2 Jun 2011, 11:38 last edited by
tnx, very powerful procedure event loop, I'm do something like theat:
@ QList<QLabel *> arr = findChildren<QLabel *>();
foreach(QLabel *lb, arr){
if(lb != NULL)
lb->installEventFilter(this);}@
-
wrote on 2 Jun 2011, 11:40 last edited by
and one more questions, what method work fast:
- Connect signal\slot
or - installEventFilter();
- Connect signal\slot
-
wrote on 2 Jun 2011, 12:07 last edited by
In terms of delivery invoking a slot or calling eventFilter() are both same or with negligible difference with an advance to eventFilter. But in this case the point of interest is how long you spend in eventFilter() hence it depends on the code inside eventFilter().
1/5