I solved the second problem with FlowLayout from Qt site: http://developer.qt.nokia.com/doc/qt...lowlayout.html
But how can I get the widget called root to expand in this code below?
FlowLayout *flowLayout = new FlowLayout;
for(int i = 0; i < 20; ++i)
{
w->setFixedSize(100, 150);
w->setStyleSheet("margin: 15px; background-color: #000000");
flowLayout->addWidget(w);
}
root->setStyleSheet("background-color: #ffff66");
root->setLayout(flowLayout);
content->setStyleSheet("background-color: #ff6600");
content->setWidget(root);
setCentralWidget(content);
QScrollArea *content = new QScrollArea(this);
FlowLayout *flowLayout = new FlowLayout;
for(int i = 0; i < 20; ++i)
{
QWidget *w = new QWidget;
w->setFixedSize(100, 150);
w->setStyleSheet("margin: 15px; background-color: #000000");
flowLayout->addWidget(w);
}
QWidget *root = new QWidget;
root->setStyleSheet("background-color: #ffff66");
root->setLayout(flowLayout);
content->setStyleSheet("background-color: #ff6600");
content->setWidget(root);
setCentralWidget(content);
To copy to clipboard, switch view to plain text mode
QScrollArea *content is orange
QWidget *root is yellow

If I remove the root QWidget and set flowLayout as a direct child of the content QScrollArea, then it works fine, but there's no scrollbar even if I force it.
EDIT: I re-implemented QMainWindow's resizeEvent() and the QWidget *root is resized every time that event takes place. Not sure if that's a good solution?
EDIT2: Well that didn't work too well. I should somehow connect the widget's size to the flowLayout probably.
EDIT3: This solution works:
{
int cWidth = content->viewport()->width();
int lNeededHeight = flowLayout->minimumHeightForWidth(cWidth);
root->setFixedWidth(cWidth);
root->setFixedHeight(lNeededHeight);
}
void MainWindow::resizeEvent(QResizeEvent *ev)
{
int cWidth = content->viewport()->width();
int lNeededHeight = flowLayout->minimumHeightForWidth(cWidth);
root->setFixedWidth(cWidth);
root->setFixedHeight(lNeededHeight);
}
To copy to clipboard, switch view to plain text mode
Any feedback on this approach? Now at leas thet root QWidget resizes itself properly:
Bookmarks