PDA

View Full Version : Qlist geometry interference with GridLayout in QT Designer



dexli
24th March 2011, 09:12
Hi all,

I try to design a dialog with QtDesigner. Inside a Group box i want the following layout

label... Spinbox1 Spinbox1
####
#....#
#....# . Lineedit
#....#
#....#
####


where ### is the listbox.

every time I try to use a grid layout the size of the list box grows to much bigger size than I need. Even if i set the sizePolicy to fixed to Minimum or every other value

How can I prevent this nasty behaviour ?

Thanks an have a nice day

dexli

high_flyer
24th March 2011, 10:57
setting maximum width must work.

ChrisW67
28th March 2011, 00:04
Or you can use the stretch parameter to QBoxLayout::addWidget() to apportion the available space in a known ratio:


#include <QtGui>
#include <QDebug>

class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p) {
QWidget *central = new QWidget(this);
QListView *list = new QListView(this);
QLineEdit *edit = new QLineEdit(this);

QHBoxLayout *layout = new QHBoxLayout(central);
layout->addWidget(list, 1); // allocate 1 unit to this
layout->addWidget(edit, 2); // and 2 units to this

central->setLayout(layout);
setCentralWidget(central);
}
public slots:
private:
};

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"


How you tweak the layout depends on exactly what behaviour you want.

dexli
28th March 2011, 12:31
Thanks for the hints.
I decide to omit the layout around this widget. This was the easiest way, because the other solutions seem to be a kind of hacking.