PDA

View Full Version : Widget proportions in QSplitter



godi
28th September 2011, 09:05
Hello,

I am having some problems with the widgets proportions in different QSplitter.

I have 3 Qsplitter and four widgets of different classes (QTreeWidget, QFrame, QTableWidget and QWidget). I create the whole structure in QtDesigner having the design and hierarchy shown in pictures 1 & 2.

The problems arrive when I want to set the widgets size before the window is shown. I have the following lines in order to try and have the figure shown in picture 3, 1/3 of the space for the first widget and 2/3 for the second one in each splitter.


ui->treeSplitter->setStretchFactor(0, 1);
ui->treeSplitter->setStretchFactor(1, 2);

ui->logSplitter->setStretchFactor(0, 1);
ui->logSplitter->setStretchFactor(1, 2);

ui->tableSplitter->setStretchFactor(0, 1);
ui->tableSplitter->setStretchFactor(1, 2);


Is there something I am missing? Could you point me out where the problem could be?

Thanks in advance.

691269136914

amleto
28th September 2011, 20:07
http://doc.qt.nokia.com/4.7/qsplitter.html#setStretchFactor



stretch is not the effective stretch factor; the effective stretch factor is calculated by taking the initial size of the widget and multiplying it with stretch.

godi
29th September 2011, 13:26
Thanks amleto. I forgot to say that I had some previous code indicating the same initial size for all the elements in the splitters.



QList<int> sizes;
sizes.append(100);
sizes.append(100);

ui->treeSplitter->setSizes(sizes);
ui->logSplitter->setSizes(sizes);
ui->tableSplitter->setSizes(sizes);


Am I using the combination of "setSize" and "setStretchFactor" in a bad way? Is there any other thing I should do apart from this?

Thanks in advance.

amleto
30th September 2011, 09:43
It looks like you may not have added the widgets already? Apart from that I'm out of ideas

godi
30th September 2011, 09:59
Hello amleto,

The code I have shown here is in the constructor of the widget and previous to those lines I have


ui->setupUi(this);

so the widget has been initalized and created for the splitter because they are place in the .ui file associated.

I think the stretch factor is not properly explained in the official documentation. In fact, I have found a link (http://www.civilnet.cn/book/embedded/gui/qt4/ch06lev1sec3.html) where it is said that setting the stretch factor to 1 for a widget while not setting it for rest of widgets in the same QSplitter objects allows the widget with stretch factor equal to one to get any additional space that is available.

I am very confused about the stretch factor.