Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QLabel and some mouse click signals
Forum Updated to NodeBB v4.3 + New Features

QLabel and some mouse click signals

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 8.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxim.prishchepa
    wrote on last edited by
    #1

    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?

    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

    1 Reply Last reply
    0
    • S Offline
      S Offline
      srikanth_trulyit
      wrote on last edited by
      #2

      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:

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxim.prishchepa
        wrote on last edited by
        #3

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

        }@

        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxim.prishchepa
          wrote on last edited by
          #4

          and one more questions, what method work fast:

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

          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

          1 Reply Last reply
          0
          • S Offline
            S Offline
            srikanth_trulyit
            wrote on last edited by
            #5

            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 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved