PDA

View Full Version : Losing palette colors when app goes out of focus.



weaver4
28th January 2020, 15:32
I have an app and on certain components I change the palette slightly. I do this by putting this code in the Widget Constructor that contains the component.


if (darkTheme) {
QPalette p = ui->strStringEdit->palette( );
p.setColor( QPalette::Active, QPalette::Base, darkPalette.color(QPalette::AlternateBase));
ui->strStringEdit->setPalette( p );
}

But when the application loses focus (by going to another application) the colors go back to the original colors. When I select my app again the modifications come back.

How do I freeze the palette?

Thanks,

Ginsengelf
28th January 2020, 15:38
Hi, you probably also need to modify the palette for QPalette::Inactive.

Ginsengelf

weaver4
28th January 2020, 16:31
Thanks! Changed my code to this and it worked!


if (darkTheme) {
QPalette p = ui->strStringEdit->palette( );
p.setColor( QPalette::Active, QPalette::Base, darkPalette.color(QPalette::AlternateBase));
p.setColor( QPalette::Inactive, QPalette::Base, darkPalette.color(QPalette::AlternateBase));
ui->strStringEdit->setPalette( p );
}