You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, October 6th 2009, 2:52pm

Layout problemsa adding widgets to bottom of layout.

Hello!

I have a window with a 2*2 grid where the top right position takes up most of the space in the window.
In the top left grid position, which is tall and narrow I would like to have som QLabels etc both in the top and in the bottom

By default they all end up in the top of course.
I have tried to arrange these widgets in a grid and using setRowMinimumHeight very large for example row 3 to push row 4 downwards. This works ok until you resize the window.
How can I put these widgets at the bottom?

grid->addWidget(label, 4,0, Qt::AlignBottom);

does not work, it still ends up just below the widget at position (3,0).

I have also tried to use QHBoxes in a QVBox (instead of a grid) but I dont know how to get some of the widgets to align to the bottom?

Thanks for your help!

2

Tuesday, October 6th 2009, 4:26pm

Quoted

I have also tried to use QHBoxes in a QVBox (instead of a grid) but I dont know how to get some of the widgets to align to the bottom?


In a box layout you can achieve that by adding a stretch between the widgets you want to separate:

Source code

1
void QBoxLayout::addStretch ( int stretch = 0 )

3

Wednesday, October 7th 2009, 9:29am

That doesnt change anything for me. Strange.

Here is the code:

void MainWindow::setupSettingsBox()
{
QWidget* dummyWidget = new QWidget( settingsBox_ ); //settingsBox_ is a QGroupBox member variable which is placed in the top left corner of the main grid.

QVBoxLayout* layout = new QVBoxLayout(dummyWidget);

{
QLabel* windSpeedLabel = new QLabel( "Wind speed:",dummyWidget );
windSpeedLabel->setFixedSize(WIDTH,HEIGHT);

windSpeedLineEdit_ = new QLineEdit(dummyWidget);
windSpeedLineEdit_->setFixedSize(WIDTH/2,HEIGHT);
windSpeedLineEdit_->setText("10");
connect(windSpeedLineEdit_, SIGNAL(textChanged(const QString &)), this, SLOT(validateLineEdits() ));

QHBoxLayout* windLayout = new QHBoxLayout();
windLayout->addWidget(windSpeedLabel);
windLayout->addWidget(windSpeedLineEdit_);

layout->addLayout(windLayout);
}

{

QLabel* sizeLabel = new QLabel( "Size:", dummyWidget );
sizeLabel->setFixedSize(WIDTH,HEIGHT);

sizeList_ = new QComboBox (dummyWidget);
sizeList_->setFixedSize(WIDTH/2,HEIGHT);
connect(sizeList_, SIGNAL(currentIndexChanged(int)), this, SLOT( sizeHasChanged()));

sizeList_->clear();

std::stringstream ss;
int index = 0;
for (unsigned int size = 5; size <= 17; ++size) {
ss.str("");
ss << size;
QString str(ss.str().c_str());
sizeList_->insertItem(index, str);
index++;
}
int defaultIndex = sizeList_->findText("12");
sizeList_->setCurrentIndex(defaultIndex);

QHBoxLayout* sizeLayout = new QHBoxLayout();
sizeLayout->addWidget(sizeLabel);
sizeLayout->addWidget(sizeList_);

layout->addStretch(100); //This line does not change anything.
layout->addLayout(sizeLayout);

}
}

4

Wednesday, October 7th 2009, 2:02pm

Ok, now I found the error.

If i dont use the dummyWidget and lets the QLabels etc have the settingsbox_ as parent it works.

(For some reason I had to use a dummyWidget before and I just did the same again...)

Thanx!!