QLabel and some mouse click signals



  • 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?



  • 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:



  • 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);

    }@



  • and one more questions, what method work fast:

    1. Connect signal\slot
      or
    2. installEventFilter();


  • 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().


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.