QLineEdit和QDateTimeEdit等含编辑框使用stylesheet配置背景透明时,鼠标进入离开背景闪烁问题的解决

tech2022-09-15  92

在使用QLineEdit和QDateTimeEdit等含编辑框的控件时如果使用stylesheet设置背景透明如下:

QLineEdit{ background-color:transparent; color:white; } QLineEdit:hover{ background-color:transparent; } QDateTimeEdit{ background-color:transparent; color:white; } QDateTimeEdit:hover{ background-color:transparent; }

这时,在界面上会显示白色,鼠标进入和离开会先显示透明又显示白色,导致闪烁问题。通过网上查找和测试,发现需要在stylesheet中增加对bolder的配置:

QLineEdit{ border: none; background-color:transparent; color:white; } QLineEdit:hover{ background-color:transparent; } QDateTimeEdit{ border: 1px solid rgb(76,91,115); background-color:transparent; color:white; } QDateTimeEdit:hover{ background-color:transparent; }

特此记录一下,也给遇到同样问题的小伙伴提供参考。

最新回复(0)