[Solved] Layout issue
-
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 -
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. -
Thanks Lukas Geyer. QDialogButtonBox solved our problem. How can I mark this thread as solved?
Thanks,
Lloyd -
You need to edit your first post and then add [Solved] to the title.
Thanks.
-
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.