[SOLVED] setAttribute and setBackgroundRole. Trying to set a dark background
-
Hello!
I've tried to set the background colour with
@setBackGroundRole(QPalette::Dark);@
But didn't work. Then I tried with
@setAttribute(Qt::WA_NoBackGround);@
And worked (at least it showed a dark screen...). I've read "this":http://qt-project.org/forums/viewthread/3239, and the "docs":http://qt-project.org/doc/qt-4.8/qwidget.html#setBackgroundRole, but I don't know why the first approach doesn't work. By the way, the doc say:
bq. You can modify the palette or set a style sheet if you don't achieve the result you want with setBackgroundRole()
If it wouldn't work, why? Somebody knows? Is there any difference between showing no background and setting a dark one?
Thanks
-
Hi QMartin,
The setBackgroundRole method let you use a color role for the background, which means one of the predefined color of the style applied to the widget. So your are basically limited to the style and its colors.
So if you don't achieve the result you want (i.e. if the style applied don't have the color/brush you want), use palette or style sheets.
Here is the style sheet way
@
myWidget->setStyleSheet("* { background-color: rgb(50, 50, 50); }");
@This will change your widget background color to a dark gray.
-
You're welcome ! :)