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:
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, ie 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
:
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!
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.