[Interest] style sheet woes

André Somers andre at familiesomers.nl
Fri Jun 14 12:56:32 CEST 2013

Please keep the discussion on the list.

Op 14-6-2013 12:51, Graham Labdon schreef:
> I set the style sheet like this -
>   	QString style = "QDialog {background-color: red;}";
> 	qApp->setStyleSheet(style);
> in the constructor of my main  window
Well, your first analysis was correct: the style sheet only gets applied 
to the widget you set it on, and any children it may have (including 
child dialogs). But as you're not making the dialog as child of te main 
window, it doesn't get applied.

So, set the stylesheet one level higher: at the application level. See 
QApplication for that. All dialogs are still part of the application, so 
a style sheet set at that level *will* get applied to the dialog.


> From: interest-bounces+graham.labdon=avalonsciences.com at qt-project.org [mailto:interest-bounces+graham.labdon=avalonsciences.com at qt-project.org] On Behalf Of André Somers
> Sent: 14 June 2013 11:45
> To: interest at qt-project.org
> Subject: Re: [Interest] style sheet woes
> Op 14-6-2013 12:33, Graham Labdon schreef:
> Hi
> I have a style sheet that sets the background colour for QDialog -
> QDialog {
>      background-color: red;
> }
> My application has a QListWidget added from Designer and is created with its containing layout as the parent,
> Upon selecting an element in the list I launch a dialog, but the style sheet is not applied to this dialog.
> I believe that this is because the list widget is not created with my main window as a parent
> I thought that by specifying the background colour in the style sheet that all dialogs (regardless of parent) would have the same background colour.
> I would be grateful if someone could explain why this is not the case
> Did you try setting it as the application-wide style sheet?
> André

You like Qt?
I am looking for collegues to join me at i-Optics!

More information about the Interest mailing list