Mouse listener
-
hi
i wanna create a class that get widgets and their positions from a frame or widget...
could you help me?
thank you -
There's something about a mouse in the title and then about widgets position? I think you need to be more specific, sorry.
-
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? -
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.
-
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; }");
@