Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt5 QWidget :hover effect delay

I am trying to create any kind of :hover effect on 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 time the mouse enters the widget until the time the effect appears.

Here's the screencast of what happens:

https://youtu.be/aNfEKabut-A

For painting 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 the CSS, i.e. don't load the CSS whatsoever, and just try to have any effect and use Qt's style, for example, this way:

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

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

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

https://youtu.be/kT10zdepsGk

Computer is rather strong, Ryzen 7 on Windows 10, and I am using VC++ 2017, so it shouldn't be related to anything like that.

If you need more code, please let me know.

Thanks!

like image 226
Dushan Savich Avatar asked Oct 29 '22 00:10

Dushan Savich


1 Answers

For fast animations with large amont of items it is recommended to use QtQuick/QML scene.

QSS is slow, because it requires a lot of recalculations and made on CPU. QGraphicsScene works faster, but again - it is CPU and requires a lot of hand-made visualization code.

like image 103
Dmitry Sazonov Avatar answered Nov 15 '22 06:11

Dmitry Sazonov