why is the background not showing when using qstackedlayout?
-
I’m writing my own messenger and I need to make 2 forms with an input and a main window. For this I decided to use qstackedlayout which will be linked to qwidget. All descendants of the form class (entrance or main window - no difference) are displayed normally, but the widget itself is not.
This is the window constructor code (which is from qwidget):
MainWindow::MainWindow(QWidget* parent) : QWidget(parent) { m_net = new NetworkController(this); m_mainScene = new MainScene(this, m_net); m_loginScene = new LoginScene(this, m_net); m_stackLayout = new QStackedLayout(this); connect(m_net, SIGNAL(succesfullLogin(QUuid)), this, SLOT(on_succesfullLogin(QUuid))); connect(m_net, SIGNAL(succesfullLogin(QUuid)), m_mainScene, SLOT(on_succesfullLogin(QUuid))); connect(m_net, SIGNAL(succesfullLogin(QUuid)), m_loginScene, SLOT(on_succesfullLogin(QUuid))); connect(m_net, SIGNAL(lostConnection()), this, SLOT(on_lostConnection())); m_stackLayout->addWidget(m_loginScene); m_stackLayout->addWidget(m_mainScene); m_stackLayout->setCurrentIndex(0); }
When you run it you get the following:
But in qt designer it looks like this:
MainScene and LoginScene are just classes inherited from qwidget, in their constructor I just call setupUi(this) and that’s it
I can’t figure out what I’m doing wrong for a long time, I hope you can help
-
@qtenjoyer Sorry, I cannot see an issue here. Your UI has a translucent box around the buttons, and that is visible in the composed UI. The background you placed it over is a matte dark grey, and the translucent box is slightly darker as you would expect.
What were you expecting?
-
@ChrisW67 said in why is the background not showing when using qstackedlayout?:
Sorry, I cannot seen an issue here. Your UI has a translucent box around the buttons, and that is visible in the composed UI. The background you placed it over is a matte dark grey, and the translucent box is slightly darker as you would expect.
What were you expecting?
but there is no yellow background that I need
-
@qtenjoyer said in why is the background not showing when using qstackedlayout?:
but there is no yellow background that I need
How have you achieved that yellow background?
-
@qtenjoyer It has nothing to do with
QStackedLayout
, the stylesheet doesn't work because you set it on a subclassedQWidget
.
You may check theQWidget
part of https://doc.qt.io/qt-6/stylesheet-reference.html. -
@qtenjoyer said in why is the background not showing when using qstackedlayout?:
that is, I cannot use stylesheet on classes inherited from qwidget? How can I realize what I want?
Your question indicates that you haven't read @Bonnie 's post carefully :)
The answer is already there :))
(Follow that link. There's an example how you can do it)