开发者

Problem in stylesheet of Qt APP

开发者 https://www.devze.com 2023-04-03 20:53 出处:网络
In my app, i have a section that is top widget, the color of the top widget is gray, and i\'ve been put severl widget on top widget, like QComboBox, QLineEdit and 2 QButton, but i have a problem when

In my app, i have a section that is top widget, the color of the top widget is gray, and i've been put severl widget on top widget, like QComboBox, QLineEdit and 2 QButton, but i have a problem when i right click on QLineEdit as you seen in below picture, the color of default context of wind开发者_开发问答ow is gray, or when i open the QComboBox the color of background is gray. I'll set the background color of two these widget to white but doesn't work. So, how can i fix this?

Sample for better understand:

http://0000.4.img98.net/out.php/i52512_problem.png

Please help me


The style sheet propagates to all the child widgets, so you have to limit their range by using the right selectors. Since the context menu is a child of the QLineEdit it is also affected.

// What you have probably done:
myLineEdit->setStyleSheet("background-color: gray");

// What you should have done:
myLineEdit->setStyleSheet("QLineEdit { background-color: gray }");      

// What you should do if there might be child widgets of the same type 
// but for which you don't want the style to apply:
myLineEdit->setObjectName("myLineEdit");
myLineEdit->setStyleSheet("QLineEdit#myLineEdit { background-color: gray }");

See "The Style Sheet Syntax - Selector Types" for details.

0

精彩评论

暂无评论...
验证码 换一张
取 消