[英]Background color of styled QLineEdit flickers
使用樣式表設置QLineEdit
的background-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.