简体   繁体   English

Qt5 QWidget:悬停效果延迟

[英]Qt5 QWidget :hover effect delay

I am trying to create any kind of :hover effect on my QWidget with the following CSS: 我试图使用以下CSS创建任何类型的:hover效果在我的QWidget上:

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. 但是,从鼠标进入小部件到效果出现的时间有2-3秒的轻微延迟。

Here's the screencast of what happens: 这是发生的事情的截屏视频:

https://youtu.be/aNfEKabut-A 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, ie don't load the CSS whatsoever, and just try to have any effect and use Qt's style, for example, this way: 即使我试图摆脱CSS,即不加载CSS,只是尝试产生任何效果并使用Qt的风格,例如,这样:

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

and just turn off the CSS, I still get the same delay. 并且只是关闭CSS,我仍然得到同样的延迟。

Here's a screencast of the same effect, without the CSS loaded and with QStyle::PE_PanelButtonBevel option selected in the paintEvent : 这是一个相同效果的截屏视频,没有加载CSS并且在paintEvent选择了QStyle::PE_PanelButtonBevel选项:

https://youtu.be/kT10zdepsGk 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. 计算机相当强大,Ryzen 7在Windows 10上,而我使用的是VC ++ 2017,所以它不应该与之类似。

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. 对于具有大量项目的快速动画,建议使用QtQuick / QML场景。

QSS is slow, because it requires a lot of recalculations and made on CPU. QSS很慢,因为它需要大量重新计算并在CPU上进行。 QGraphicsScene works faster, but again - it is CPU and requires a lot of hand-made visualization code. QGraphicsScene工作得更快,但又一次 - 它是CPU,需要大量手工制作的可视化代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM