Qwidget how to highlight widget under cursor

I created some types of QLabel widgets in QT and added this to QToolbar. I want to highlight a specific widget that is under the cursor. I can’t figure out how to do this. Can anyone help? I need this information in QT 4.

Thanks.

+3
source share
1 answer

You have several options. First, as a subclass of QLabel, you can handle mouse events directly in your class. Be sure to use QWidget :: setMouseTracking () to enable this. In such a scenario, you can do whatever you want, but you will have to redefine the drawing procedure so that your class can draw itself in a certain way.

Unfortunately, QLabel does not support the state of hover stylesheets, so you cannot do this easily with sheet styles. However, if you are considering a subclass from QPushButton, you can get this great feature so that with CSS you get a nice high intensity effect. For more information about QT style sheets, see here .

QPushButton , . , , :

QPushButton:hover {
     background-color: black;
 }
QPushButton:hover {
     background-color: white;
 }

>

+9

Source: https://habr.com/ru/post/1720659/


All Articles