stylsheet is not working in main widget
-
qt 5.11.1 , linux.
i applied this stylesheet in the main widget .QWidget { background-color: #1C2836; color: #ffffff; }the widget shows fine in designer.

after build i am seeing it is only applied in the label ,buttons not in the main widgets backgrounds and SPACING .

when add another widget in the main widget and apply stylesheet on that secind widget it works fine. like this

-
Like in List of Stylable Widgets said, QWidget only supports 3 style properties: background, background-clip, background-origin.
You might using QPalette:m_myWidget = new QWidget(this); m_myWidget->setGeometry(0, 0, 300, 100); QPalette pal = palette(); // set black background pal.setColor(QPalette::Background, Qt::black); m_myWidget->setAutoFillBackground(true); m_myWidget->setPalette(pal); m_myWidget->show();from: https://wiki.qt.io/How_to_Change_the_Background_Color_of_QWidget
-
Like in List of Stylable Widgets said, QWidget only supports 3 style properties: background, background-clip, background-origin.
You might using QPalette:m_myWidget = new QWidget(this); m_myWidget->setGeometry(0, 0, 300, 100); QPalette pal = palette(); // set black background pal.setColor(QPalette::Background, Qt::black); m_myWidget->setAutoFillBackground(true); m_myWidget->setPalette(pal); m_myWidget->show();from: https://wiki.qt.io/How_to_Change_the_Background_Color_of_QWidget
-
Hi
Try to set
setAutoFillBackground(true); for Wbattery
(its a property so you can do in Designer)
Also, did you set the layouts margins to zero- so there is no spaces ?

I think what you are seeing is once you use wBattery in app,
it get more space, so layout spaces the items. Widgets have
no background pr default so you look through and see the other window under it.Depending on what you need, you might also want to set its maximumsize so it stays like in Designer. Else when you insert in some other widget, it might be bigger if more space for it.

Only do this if goal is to stay same size even when mainwindow resizes. -
Hi
Try to set
setAutoFillBackground(true); for Wbattery
(its a property so you can do in Designer)
Also, did you set the layouts margins to zero- so there is no spaces ?

I think what you are seeing is once you use wBattery in app,
it get more space, so layout spaces the items. Widgets have
no background pr default so you look through and see the other window under it.Depending on what you need, you might also want to set its maximumsize so it stays like in Designer. Else when you insert in some other widget, it might be bigger if more space for it.

Only do this if goal is to stay same size even when mainwindow resizes. -
i need those spaces for looks. so i gess i have to add padding in qstylesheet to get those spaces.
thanks.
-
@saber
Well the margins for layout works just as well.
so maybe just setAutoFillBackground look like you want.