繁体   English   中英

样式为QLineEdit的背景色闪烁

[英]Background color of styled QLineEdit flickers

使用样式表设置QLineEditbackground-color ,将鼠标悬停在控件上时会出现非常明显的闪烁。 示例代码:

QLineEdit* flicker = new QLineEdit(this);
flicker->setStyleSheet("QLineEdit {background: red;}");
flicker->show();

仅在Windows Vista和更高版本(而不是XP)上运行时会发生这种情况。 我认为这与Windows(Aero?)应用程序的默认样式有关,因为将样式设置为QStyle::Fusion解决此问题:

QLineEdit* flicker = new QLineEdit(this);
QStyle* fusion = QStyleFactory::create(QString("Fusion"));
flicker->setStyle(fusion);
flicker->setStyleSheet("QLineEdit {background: red;}");
flicker->show();

编辑:我还设置了一个eventfilter器,以便在鼠标悬停时重新绘制控件,并且调试器确认立即调用了该函数。

遇到相同的问题,并希望分享一个可能的解决方法:

鼠标悬停时QLineEdit闪烁的原因可能是“ QLineEdit:hover {...}”使用了另一个样式表,该样式表仍包含默认值。 不幸的是,添加“ QLineEdit:hover {background-color:red}”似乎还不够。 我发现它直到现在仍能正常工作的唯一方法是使用

flicker->setStyleSheet("QLineEdit{background-color: red;} QLineEdit:hover{border: 1px solid gray; background-color red;}");

不太确定为什么需要显式设置border属性,但是它对我有用。

我遇到了类似的问题,并通过向QLineEdit添加边框来解决它,如下所示:

#dont_flick_lineedit{
    background-color: red;
    border: 1px solid #CCC;
}
#flick_lineedit{
    background-color: blue;
}

暂无
暂无

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

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