PDA

View Full Version : Please help me in layout coding



mahesh113
31st May 2012, 05:48
I was asked in an interview to add a pushbutton on the window which should appear on the bottom-right corner of the window. I told him we can do it with setGeometry(..) function. But he wasn't satisfied. He asked me to do it with layouts. My partial answer to him was to add the button in the bottom cell of the QVBoxlayout, but that will not show the button on the desired corner of the window.
Please help me with the code for this.

ChrisW67
31st May 2012, 06:52
QGridLayout might be one way.

wysota
31st May 2012, 07:26
... another would be a QVBoxLayout like you said, containing a QHBoxLayout with a spacer and the button. A geek solution could be to use QDialogButtonBox.

mahesh113
31st May 2012, 10:59
Thanks for your answer, but can you please help me how to the code for this?

Santosh Reddy
31st May 2012, 12:21
Here is one way


QWidget* widget = new QWidget(this);
QGridLayout* layout = new QGridLayout(widget);
QPushButton* button = new QPushButton("Bottom Left Corner", this);
layout->addWidget(button);
layout->setAlignment(Qt::AlignBottom | Qt::AlignRight);