Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QScrollArea and floating widgets
Qt 6.11 is out! See what's new in the release blog

QScrollArea and floating widgets

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kobid
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • clogwogC Offline
      clogwogC Offline
      clogwog
      wrote on last edited by
      #2

      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 ?

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        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...

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kobid
          wrote on last edited by
          #4

          This is exactly what I needed! Thanks! Qt Creator should have it as one of it standard layouts

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kobid
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved