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. Mouse listener
Forum Updated to NodeBB v4.3 + New Features

Mouse listener

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.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
    mohamaddanesh44
    wrote on last edited by
    #1

    hi
    i wanna create a class that get widgets and their positions from a frame or widget...
    could you help me?
    thank you

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      There's something about a mouse in the title and then about widgets position? I think you need to be more specific, sorry.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mohamaddanesh44
        wrote on last edited by
        #3

        you're right :)
        i want their positions for some mouse events e.g. when cursor goes to a label i want it to be highlighted
        did you get it?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          butterface
          wrote on last edited by
          #4

          All objects know their children , so you can iterate over them. Also you should have a look at https://qt-project.org/doc/qt-4.8/qapplication.html https://qt-project.org/doc/qt-4.8/qwidget.html and https://qt-project.org/doc/qt-4.8/qmouseevent.html which should provide everything you need.

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            You shouldn't track widgets and mouse position to do that. There are too many corner cases where it won't work.

            Instead use "enterEvent":http://qt-project.org/doc/qt-5.1/qtwidgets/qwidget.html#enterEvent and "leaveEvent":http://qt-project.org/doc/qt-5.1/qtwidgets/qwidget.html#leaveEvent or, if you're not subclassing widgets, you can install an "event filter":http://qt-project.org/doc/qt-5.1/qtcore/qobject.html#installEventFilter and check for the QMouseEvent of type QEvent::Enter and QEvent::Leave

            But if it's only for simple label highlighting it's a lot lot easier with a stylesheet:
            @
            yourLabelOrAnyOfLabelParents->
            setStyleSheet("QLabel:hover { color: red; }");
            @

            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