Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. why is the background not showing when using qstackedlayout?
Qt 6.11 is out! See what's new in the release blog

why is the background not showing when using qstackedlayout?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 789 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qtenjoyer
    wrote on last edited by
    #1

    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:
    ed7c4fbf-1f7d-4ad7-a4d7-2542e11b714f-image.png

    But in qt designer it looks like this:
    7f08e07b-c84f-4bd6-8058-e6e5caf40bd9-image.png

    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

    C 1 Reply Last reply
    0
    • Q qtenjoyer

      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:
      ed7c4fbf-1f7d-4ad7-a4d7-2542e11b714f-image.png

      But in qt designer it looks like this:
      7f08e07b-c84f-4bd6-8058-e6e5caf40bd9-image.png

      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

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by ChrisW67
      #2

      @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?

      Q 1 Reply Last reply
      1
      • C ChrisW67

        @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?

        Q Offline
        Q Offline
        qtenjoyer
        wrote on last edited by
        #3

        @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

        C 1 Reply Last reply
        0
        • Q qtenjoyer

          @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

          C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          @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?

          Q 1 Reply Last reply
          1
          • C ChrisW67

            @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?

            Q Offline
            Q Offline
            qtenjoyer
            wrote on last edited by
            #5

            @ChrisW67 via stylesheeta121ccde-5970-467a-bc1a-822c9730f5d1-image.png

            B 1 Reply Last reply
            0
            • Q qtenjoyer

              @ChrisW67 via stylesheeta121ccde-5970-467a-bc1a-822c9730f5d1-image.png

              B Offline
              B Offline
              Bonnie
              wrote on last edited by
              #6

              @qtenjoyer It has nothing to do with QStackedLayout, the stylesheet doesn't work because you set it on a subclassed QWidget.
              You may check the QWidget part of https://doc.qt.io/qt-6/stylesheet-reference.html.

              Q 1 Reply Last reply
              2
              • B Bonnie

                @qtenjoyer It has nothing to do with QStackedLayout, the stylesheet doesn't work because you set it on a subclassed QWidget.
                You may check the QWidget part of https://doc.qt.io/qt-6/stylesheet-reference.html.

                Q Offline
                Q Offline
                qtenjoyer
                wrote on last edited by
                #7

                @Bonnie that is, I cannot use stylesheet on classes inherited from qwidget? How can I realize what I want?

                Pl45m4P 1 Reply Last reply
                0
                • Q qtenjoyer

                  @Bonnie that is, I cannot use stylesheet on classes inherited from qwidget? How can I realize what I want?

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by
                  #8

                  @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)


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved