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. GridLayout and ScrollArea
Qt 6.11 is out! See what's new in the release blog

GridLayout and ScrollArea

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 4.8k 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.
  • F Offline
    F Offline
    fouffa89
    wrote on last edited by
    #1

    I have a scrollArea wich contains a list of widgets (progressbar, label,tool button)
    @
    gridl->addWidget(w);
    ui->scroll->setLayout(gridl);
    @
    gridl is a gridLayout.

    Is it possible to update widgets position on click event?
    for exemple: switching between lines (line3<--line2, line2<--line3)
    I'm obliged to call @ui->scroll->setLayout(gridl);@ when I make some changes on the GridLayout
    I'm lost please help me.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bodzio131
      wrote on last edited by
      #2

      [quote author="fouffa89" date="1365158146"]
      Is it possible to update widgets position on click event?
      [/quote]

      What about QScrollArea mouse events methods?

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fouffa89
        wrote on last edited by
        #3

        I have no idea how to do it but I will search for some example , thanks a lot , your post was helpful.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          b1gsnak3
          wrote on last edited by
          #4

          another solution would be to have a method in which you create a new gridLayout, add the existing items to that layout, call scrollArea->layout()->deleteLater(); and after call scrollArea->setLayout(new gridLayout);

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fouffa89
            wrote on last edited by
            #5

            yes this is my solution for now but I'm searching for the best solution to do it. The problem is how to make some changes without loading all the gridlayout?

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bodzio131
              wrote on last edited by
              #6

              I don't understand why you need to load whole layout. I tried myself and every change in layout is visible automatically (Qt5.0.2, VS2012). See below at my simple test, it changes layout after 5 seconds in timer event (moves label '3' from position 4 to 1). Please, forgive slummy example, I used box layout instead of grid for simplicity.

              @
              #include <QtWidgets\qapplication.h>
              #include <QtWidgets\qwidget.h>
              #include <QtWidgets\qscrollarea.h>
              #include <QtWidgets\qlabel.h>
              #include <QtWidgets\qboxlayout.h>
              #include <QtCore\qstring.h>

              class MyScrollArea
              : public QScrollArea
              {
              public:
              MyScrollArea()
              {
              //prepare layout elements
              m_mainLayout = new QVBoxLayout;

              for ( int i = 0; i < 10; ++i )
              {
              QLabel * label( new QLabel( QString::number( i ) ) );
              m_mainLayout->addWidget( label );
              m_labels.push_back( label );
              }

              //set layout container
              QWidget *widget( new QWidget );
              widget->setLayout( m_mainLayout );
              setWidget( widget );

              //start timer
              startTimer( 5000 );
              }

              void timerEvent( QTimerEvent * )
              {
              //change layout
              m_mainLayout->removeWidget( m_labels[ 3 ] );
              m_mainLayout->insertWidget( 0, m_labels[ 3 ] );
              }

              QVBoxLayout m_mainLayout;
              QVector< QLabel
              > m_labels;

              };

              int main( int _argc, char** _argv )
              {
              QApplication app( _argc, _argv );

              MyScrollArea scrollArea;
              scrollArea.setMaximumHeight( 100 );
              scrollArea.show();

              return app.exec();
              }
              @

              1 Reply Last reply
              0
              • F Offline
                F Offline
                fouffa89
                wrote on last edited by
                #7

                You're right , I never thought that it was as simple as that ,Thanks a lot!

                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