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. [Solved] Layout issue
Forum Updated to NodeBB v4.3 + New Features

[Solved] Layout issue

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.1k 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.
  • L Offline
    L Offline
    lloydqt
    wrote on last edited by
    #1

    Hi,

    We are creating a tabbed dialog. I am adding a code snippet, so it will be easier for you to understand.
    @MyDialog::MyDialog(QWidget parent): QDialog(parent)
    {
    MainIFaceTab = new QTabWidget(this);
    MainIFaceTab->addTab(new ViewUser,"View");
    MainIFaceTab->addTab(new AddUser,"Add User");
    QVBoxLayout
    qvbl=new QVBoxLayout;
    qvbl->addWidget(MainIFaceTab);
    QHBoxLayout *qhbl=new QHBoxLayout();
    btnClose=new QPushButton("&Close",this);
    btnAdd=new QPushButton("&Add",this);
    qhbl->addWidget(btnClose,0,Qt::AlignRight);
    qhbl->addWidget(btnAdd,0,Qt::AlignRight);
    qhbl->stretch(0);
    btnAdd->setEnabled(false);
    qvbl->addItem(qhbl);
    setLayout(qvbl);
    connect(MainIFaceTab, SIGNAL(currentChanged(int)), SLOT(TabChange(int)));
    }@

    The problem here is that, we want the button at the bottom right corner of the dialog. But when this dialog is displayed, the buttons are shown apart one at the right and at the middle. (Properly saying if we split the dialog vertically in to two, the two buttons are at the right of each half).

    How are we doing wrong, how can we solve this?

    Thanks,
    Lloyd

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      It is <code>addStretch()</code>, not <code>stretch()</code> (which just returns the stretch factor of a given item).
      @
      btnClose = new QPushButton("&Close", this);
      btnAdd = new QPushButton("&Add", this);
      qhbl->addStretch();
      qhbl->addWidget(btnClose, 0, Qt::AlignRight);
      qhbl->addWidget(btnAdd, 0, Qt::AlignRight);
      btnAdd->setEnabled(false);
      @
      You should consider using QDialogButtonBox instead, which presents buttons in a layout that is appropriate to the current widget style.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lloydqt
        wrote on last edited by
        #3

        Thanks Lukas Geyer. QDialogButtonBox solved our problem. How can I mark this thread as solved?

        Thanks,
        Lloyd

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          You need to edit your first post and then add [Solved] to the title.

          Thanks.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            There is unfortunately no automatism to mark posts as solved "yet":http://qt-project.org/forums/viewforum/46/, so just prepend the inital post title with [Solved], as Sam already suggested.

            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