Reputation: 11818
Im implementing a Widget which is basically a list of buttons (which represent a file structure). It looks like this:
[[recentFolder] // bar
[(stretch)
[folderA], // foo
[folderB], // programs
[folderC], // c:
(stretch)]
[rootDir]] // my computer
I hope you can see the three widgets in my layout: A folderbutton for the most recent folder at the top, a folderbutton for the root folder at the bottom and a widget which displays many folderbuttons in the middle. All folderbuttons are fixed width and height. I added stretch areas at the top/bottom of the center widget because thats the only widget which should be able to resize (expanding policy in height). But when I resize the parent widget, it looks like this:
[[recentFolder] // bar
// empty space does not
// belong to any child
[(stretch)
[folderA], // foo
[folderB], // programs
[folderC], // c:
(stretch)]
// empty space does not
// belong to any child
[rootDir]] // my computer
which means the center widget does not get any resize event at all. I need it to resize like that:
[[recentFolder] // bar
[
// child was resized
(stretch)
[folderA], // foo
[folderB], // programs
[folderC], // c:
(stretch)
// child was resized
]
[rootDir]] // my computer
As you can (should) see, my stretch areas have no effect at all and do not work as I thougth they would. Im coming from .NET and miss the way how I could dock controls in the parent so they use up all the existing space. Any idea how to do this in Qt 4?
Right now im calling setGeometry()
on my center child within the parents resize event, which works but bypasses the layout manager.
Upvotes: 0
Views: 1279
Reputation: 11818
after a few days of serious wtf!? I found out the reason why my widgets did not resize properly. I still do not know why this happens, so if someone was kind enough to explain it to me, his answer will be marked as correct instead of mine.
Facts:
I added the three widgets on my main widget like this:
QVBoxLayout* layout = new QVBoxLayout();
this->setLayout(layout);
layout->addWidget(recent, 0, Qt::AlignTop | Qt::AlignCenter);
layout->addWidget(list, 1, Qt::AlignTop | Qt::AlignCenter);
layout->addWidget(root, 0, Qt::AlignTop | Qt::AlignCenter);
As soon as I removed the alignment stuff, everything works as expected:
QVBoxLayout* layout = new QVBoxLayout();
this->setLayout(layout);
layout->addWidget(recent);
layout->addWidget(list);
layout->addWidget(root);
Upvotes: 1