gpt4 book ai didi

c++ - 样式化的 QLineEdit 的背景颜色闪烁

转载 作者:可可西里 更新时间:2023-11-01 11:18:34 24 4
gpt4 key购买 nike

使用样式表设置 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 属性,但它对我有用。

关于c++ - 样式化的 QLineEdit 的背景颜色闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24742851/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com