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. Layout centering on QStackedWidget
Forum Updated to NodeBB v4.3 + New Features

Layout centering on QStackedWidget

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 5.9k Views 1 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.
  • V Offline
    V Offline
    veeeee_d
    wrote on last edited by
    #1

    I'm writing a program that uses a QTabWidget as its base. To avoid putting everything in the same place, I'm using a QStackedWidget in one of the tabs so I can put several stuff there, which is a good idea for me.
    The problem is, I designed (on Qt Designer) a simple login form, but the problem is I can't seem to be able to center my design on the QStackedWdiget, the layout is always aligned to top-left. I have managed to use a QGridLayout to fake a CSS-like padding design, but I would really like to keep the layout I designed fixed-sized, and it is impossible with QGridLayout, as we all know.
    The question is: how can I have my layout centered in the widget, such that the widget would only fill the surrounds much like we can do in QML with the anchors?

    Thanks in advance.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mabrouk
      wrote on last edited by
      #2

      you can use spacers to move your form into the center
      else you can use the alignment parameter in "QBoxLayout::addWidget(QWidget * widget, int stretch = 0, Qt::Alignment alignment = 0)":http://doc.qt.nokia.com/4.7/qboxlayout.html#addWidget to align the elements in the center, but you have to layout the form using code and not designer

      1 Reply Last reply
      0
      • V Offline
        V Offline
        veeeee_d
        wrote on last edited by
        #3

        Thanks for the answer, but the main problem is that QStackedWidget treats my widget as the page itself, therefore I can't add a Widget to the layout, since my Widget is the page itself.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mabrouk
          wrote on last edited by
          #4

          well, i never used QStackedWidget before, but you can use this turn around, add your widget to a layout and add this layout to an empty widget and use this one to be the page of the QStackedWidget

          1 Reply Last reply
          0
          • V Offline
            V Offline
            veeeee_d
            wrote on last edited by
            #5

            I added a layout to the QBoxLayout, it looks like it works alright this way.
            Thanks for the help.

            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