QScrollArea and floating widgets
-
Hi. I have QScrollArea with a lot of buttons (or other widgets) created at runtime. The idea is that scroll area has only vertical scrollbar. If some widget can't fit in current line/row then it jump to next line/row. It should work like "word wrap". I can't show picture example, but lets say that you have web browser or better QPlainTextEdit. If it contains a big text and you change its size, then words are wrapped vertically. I need similar solution with QScrollArea and childs widgets. I'm playing with Frame and Grid layout properties but can't find solution.
Regards
-
i could be wrong but it sounds like you are describing a flow layout
http://qt-project.org/doc/qt-4.8/layouts-flowlayout.html ? -
use QScrollArea::setWidgetResizable(true) and use the "Flow Layout":http://qt-project.org/doc/qt-4.8/layouts-flowlayout.html.
You may need to tweak the layout to your needs... -
This is exactly what I needed! Thanks! Qt Creator should have it as one of it standard layouts
-
Hm, flowlayout is working perfect but seems that it can't cooperate with QScollArea. I mean, when I change size of QScrollArea to very small (content in flowlayout can't fit anymore) scroll don't refresh (even if they are always on). This is my simple test:
@MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);FlowLayout *l = new FlowLayout; l->addWidget(new QPushButton("Test")); l->addWidget(new QPushButton("Test")); l->addWidget(new QPushButton("Test")); l->addWidget(new QPushButton("Test")); l->addWidget(new QPushButton("Test")); l->addWidget(new QPushButton("Test")); l->addWidget(new QPushButton("Test")); l->addWidget(new QPushButton("Test")); l->addWidget(new QPushButton("Test")); l->addWidget(new QPushButton("Test")); l->addWidget(new QPushButton("Test")); l->addWidget(new QPushButton("Test")); l->addWidget(new QPushButton("Test")); l->addWidget(new QPushButton("Test")); l->addWidget(new QPushButton("Test")); ui->scrollArea->setLayout(l);
}@
MainWindow central widget has gridlayout so QScrollArea is stretched to main window size. When I resize main window, scrollbars don't update.
Edit: Ok, this topic solved problem with scrollbars:
http://qt-project.org/forums/viewthread/12233