Monday, November 6, 2017

Qt5 QWidget :hover effect delay

Leave a Comment

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!

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment