PDA

View Full Version : How to keep buttons close to each other (horizontally) in Qt widget?



TheIndependentAquarius
26th September 2012, 07:43
QGridLayout *layout = new QGridLayout ();
centralWidget->setLayout (layout);
layout->addWidget (refresh, 0, 0);
layout->addWidget (zoomIn, 1, 0);
layout->addWidget (zoomOut, 1, 1);
layout->addWidget (panLeft, 2, 0);
layout->addWidget (panRight, 2, 1);
layout->addWidget (panTop, 3, 0);
layout->addWidget (panBottom, 3, 1);
layout->addWidget (findInfo, 4, 0);
layout->addWidget (textEdit, 5, 0);

window->setCentralWidget (centralWidget);

See the screen shot attached.
8255

Robbie
26th September 2012, 09:28
The big gap you've got is caused by the size of textEdit. You could do two things:

1. You could make textEdit span two columns using QGridLayout::addWidget(QWidget * widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment = 0)

2. You could put all the buttons in a QGridLayout and then add that as the first element in a QVBoxLayout, with textEdit as the second element.

wyjyan
26th September 2012, 11:13
Yo

set rowSpan, columnSpan for widgets in QGridLayout::addWidget()




Ex:

layout->addWidget (panBottom, 3, 1, 1, 1);
layout->addWidget (findInfo, 4, 0, 1, 1);
layout->addWidget (textEdit, 5, 0, 1, 2);