[Interest] Howto keep a pushButton style while changing the backgroundcolor

Tony Rietwyk tony at rightsoft.com.au
Mon Apr 25 19:38:09 CEST 2016


Anton said: 

> Sent: Tuesday, 26 April 2016 2:53 AM
> Hi,
> 
> I am experimenting with qt 5.6.0.
> 
> 1. I create a QtWidgts application.
> 2. I drop a pushButton in the Main Window 3. I change the styleSheet of
the
> QMainWindow
>    to: background-color: rgb(85, 170, 255);
> 
> Now the button has the same background color too.
> 
> How can I leave the style of the pushbutton as it is?
> (without inheriting the blue background color from the QMainWindow)
> 
> I didn't find any solution and I do not want to set a background bitmap
for
> such a simple problem.
> 
> What point did I miss?
> 
> Thanks for a hint.
> 
> Anton

You missed some CSS.  Without a CSS selector, the background-color
recursively applies to all widgets parented by the main window. 

Try setStyleSheet( "QMainWindow { background-color: rgb(85, 170, 255); }" );
or
      setStyleSheet( "#mainWindowObjectName { background-color: rgb(85, 170,
255); }" ); 

Hope that helps, 

Tony





More information about the Interest mailing list