PDA

View Full Version : Setting background-color on widgets makes child widget wrong style



Aladdina
30th March 2009, 14:02
Hi,

I'm new to Qt and have a problem with my first Qt application.
Steps to recreate on Windows Vista (fairly simple):
1. Start Qt Designer and create a mainwindow ui, add a push button to main widget "centralWidget"
2. Change the stylesheet of either "MainWindow" or "centralWidget" from Property Editor, and set it's background to white: background-color: rgb(255, 255, 255);
Issues: the button on the widget doesn't render as expected, please refer to the images below. The image on left side is a default preview result, and it's a Vista Style button. The one on right side is the result with white background and it's a very old windows style.
http://www.qtforum.org/index.php?page=Attachment&attachmentID=2017&h=61cec0c41a0cca36d6118f6b83790f1598fda8a8http://www.qtforum.org/index.php?page=Attachment&attachmentID=2018&h=32c846cf835b7fd77fc2edf5541a68416ad79aa3

Thanks

Aladdina
30th March 2009, 14:28
Finally I used the code like this to change the palette, and it works well so far:


QPalette pal = palette();
pal.setColor( QPalette::Window, Qt::white );
setPalette( pal );

Note:
1. The preview for setting the palette from Qt Designer doesn't work. I wasted much time because of this defect.
2. I tried to override virtual void paintEvent ( QPaintEvent * event );, haven't finished yet, not sure what will happen.