Qt5 QWidget: freeze effect hover

I am trying to create some kind of effect :hover for my QWidget with the following CSS:

 QWidget.mis--MyButton { width: 300px; height: 300px; background: white; /*cursor: pointer;*/ font-family: Calibri; border-radius: 10px; border: 2px solid rgb(218, 218, 218); /*#007FEB;*/ padding: 1px; margin-top: 2px; } QWidget.mis--MyButton:hover { border: 2px solid #007FEB; /*#007FEB;*/ } 

However, there is a slight delay of 2-3 seconds from the moment you enter the mouse into the widget until the effect appears.

Here is a screencast of what happens:

https://youtu.be/aNfEKabut-A

For drawing, I use the following code:

 void MyButton::paintEvent(QPaintEvent * event) { QStyleOption opt; opt.init(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } 

Even when I try to get rid of CSS, i.e. I don’t load CSS at all, and just try to get some effect and use the Qt style, for example, as follows:

 style()->drawPrimitive(QStyle::PE_PanelButtonBevel, &opt, &p, this); 

and just turn off CSS, I still get the same delay.

Here's a screencast of the same effect, with no CSS loaded and with the QStyle::PE_PanelButtonBevel parameter selected in paintEvent :

https://youtu.be/kT10zdepsGk

The computer is pretty strong, Ryzen 7 on Windows 10, and I'm using VC ++ 2017, so it should not be related to anything like that.

If you need more code, please let me know.

Thanks!

+5
source share
1 answer

For fast animations with a lot of elements, it is recommended to use the QtQuick / QML scene.

QSS is slow because it requires a lot of recalculations and is done on the CPU. QGraphicsScene is faster, but again it is a processor and requires a lot of visualization code manually.

+2
source

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


All Articles