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. Multiple identical QSliders do not resize properly on window resize
Forum Update on Monday, May 27th 2025

Multiple identical QSliders do not resize properly on window resize

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 789 Views
  • 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.
  • M Offline
    M Offline
    Mathijsco
    wrote on last edited by
    #1

    Re: [QSlider inside layout](update on resize.)

    When I have multiple, identical QSliders, with the same settings and the same value, the sliders do not resize properly when the main window is resized. When the value of at least one slider is different from the others the resizing works as expected. I'm using Qt 5.13.0 on macOS 10.14.6.

    When running the example code below and resizing the window, this is the result which is not expected:
    0_1564923759857_Schermafbeelding 2019-08-04 om 15.01.34.png
    When the value of one of the sliders is changed to be different from the other, and the window is resized again, this is the result which looks as expected:
    0_1564923764398_Schermafbeelding 2019-08-04 om 15.01.43.png

    Minimal example that shows the effect

        MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent)
    {
        auto w = new QWidget;
        auto layout = new QGridLayout(w);
        setCentralWidget(w);
    
        auto slider1 = new QSlider;
        slider1->setMinimum(0);
        slider1->setMaximum(20);
        slider1->setOrientation(Qt::Horizontal);
        slider1->setTickInterval(5);
        slider1->setTickPosition(QSlider::TicksBelow);
        layout->addWidget(slider1, 0, 0);
    
        auto slider2 = new QSlider;
        slider2->setMinimum(0);
        slider2->setMaximum(20);
        slider2->setOrientation(Qt::Horizontal);
        slider2->setTickInterval(5);
        slider2->setTickPosition(QSlider::TicksBelow);
        layout->addWidget(slider2, 1, 0);
    }
    
    Pl45m4P 1 Reply Last reply
    0
    • M Mathijsco

      Re: [QSlider inside layout](update on resize.)

      When I have multiple, identical QSliders, with the same settings and the same value, the sliders do not resize properly when the main window is resized. When the value of at least one slider is different from the others the resizing works as expected. I'm using Qt 5.13.0 on macOS 10.14.6.

      When running the example code below and resizing the window, this is the result which is not expected:
      0_1564923759857_Schermafbeelding 2019-08-04 om 15.01.34.png
      When the value of one of the sliders is changed to be different from the other, and the window is resized again, this is the result which looks as expected:
      0_1564923764398_Schermafbeelding 2019-08-04 om 15.01.43.png

      Minimal example that shows the effect

          MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent)
      {
          auto w = new QWidget;
          auto layout = new QGridLayout(w);
          setCentralWidget(w);
      
          auto slider1 = new QSlider;
          slider1->setMinimum(0);
          slider1->setMaximum(20);
          slider1->setOrientation(Qt::Horizontal);
          slider1->setTickInterval(5);
          slider1->setTickPosition(QSlider::TicksBelow);
          layout->addWidget(slider1, 0, 0);
      
          auto slider2 = new QSlider;
          slider2->setMinimum(0);
          slider2->setMaximum(20);
          slider2->setOrientation(Qt::Horizontal);
          slider2->setTickInterval(5);
          slider2->setTickPosition(QSlider::TicksBelow);
          layout->addWidget(slider2, 1, 0);
      }
      
      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @mathijsco

      I doubt that the slider value influences the size policies of your widgets.

      Try to set a parent (your mainWindow) to your sliders. It may fix it

      auto slider1 = new QSlider(this);
      // Same with slider2
      
      

      Edit:
      Maybe some invisible layout items (plaaceholders from your Grid) are blocking the expansion of your sliders, in fact you are using a GridLayout.
      What does it look like, when you use QHBoxLayout / QVBoxLayout?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      M 1 Reply Last reply
      0
      • D dangquan091

        This post is deleted!

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #3

        @dangquan091

        The line where you add slider2 to your Layout is missing (I guess a typo).
        But nevertheless, I added the missing line and it works for me on Windows.

        So maybe it`s a macOS problem (Qt code doesnt look wrong).


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        1
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi
          This reminds me a bit of the posters having issues on MacOs with refresh
          of widgets.
          https://bugreports.qt.io/browse/QTBUG-68740
          However, here in this post, it seems layout related so not sure its the same reason.

          M 1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @mathijsco

            I doubt that the slider value influences the size policies of your widgets.

            Try to set a parent (your mainWindow) to your sliders. It may fix it

            auto slider1 = new QSlider(this);
            // Same with slider2
            
            

            Edit:
            Maybe some invisible layout items (plaaceholders from your Grid) are blocking the expansion of your sliders, in fact you are using a GridLayout.
            What does it look like, when you use QHBoxLayout / QVBoxLayout?

            M Offline
            M Offline
            Mathijsco
            wrote on last edited by
            #5

            @pl45m4 said in Multiple identical QSliders do not resize properly on window resize:

            @mathijsco

            I doubt that the slider value influences the size policies of your widgets.

            I don't know what it does, but if the sliders have different values they behave okay, if the values (and other settings) are identical they do not.

            Try to set a parent (your mainWindow) to your sliders. It may fix it

            This did not help.

            Maybe some invisible layout items (plaaceholders from your Grid) are blocking the expansion of your sliders, in fact you are using a GridLayout.
            What does it look like, when you use QHBoxLayout / QVBoxLayout?

            It behaves exactly the same with a QVBoxLayout. There are no other items, the code I posted above is all there's needed to obtain this behaviour.

            Pl45m4P 1 Reply Last reply
            0
            • M Mathijsco

              @pl45m4 said in Multiple identical QSliders do not resize properly on window resize:

              @mathijsco

              I doubt that the slider value influences the size policies of your widgets.

              I don't know what it does, but if the sliders have different values they behave okay, if the values (and other settings) are identical they do not.

              Try to set a parent (your mainWindow) to your sliders. It may fix it

              This did not help.

              Maybe some invisible layout items (plaaceholders from your Grid) are blocking the expansion of your sliders, in fact you are using a GridLayout.
              What does it look like, when you use QHBoxLayout / QVBoxLayout?

              It behaves exactly the same with a QVBoxLayout. There are no other items, the code I posted above is all there's needed to obtain this behaviour.

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by Pl45m4
              #6

              @mathijsco

              Isn`t this post the same as this one here (https://forum.qt.io/topic/105679/multiple-identical-qsliders-do-not-resize-properly-on-window-resize)?

              I copied the code into an empty project to test it and it worked for me like it should.
              Do you have any slots connected to your value-changed signal?


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              M 1 Reply Last reply
              1
              • Pl45m4P Pl45m4

                @mathijsco

                Isn`t this post the same as this one here (https://forum.qt.io/topic/105679/multiple-identical-qsliders-do-not-resize-properly-on-window-resize)?

                I copied the code into an empty project to test it and it worked for me like it should.
                Do you have any slots connected to your value-changed signal?

                M Offline
                M Offline
                Mathijsco
                wrote on last edited by
                #7

                @pl45m4 said in Multiple identical QSliders do not resize properly on window resize:

                @mathijsco

                Isn`t this post the same as this one here (https://forum.qt.io/topic/105679/multiple-identical-qsliders-do-not-resize-properly-on-window-resize)?

                Wow, it looks like a spambot just copied my post. That's not my account but it is my post (but partially).

                I copied the code into an empty project to test it and it worked for me like it should.
                Do you have any slots connected to your value-changed signal?

                This code is all there is. No slots connected (if I do connect slots however, the problem persists). Could it be a mac specific issue? I encountered this issue first in a larger project with all kinds of other stuff in it. I created this small example to see if it was a Qt issue or something in my code. The small example showed the exact same problem so it does seem to be a Qt thing (at least on macOS).

                Pl45m4P 1 Reply Last reply
                3
                • M Mathijsco

                  @pl45m4 said in Multiple identical QSliders do not resize properly on window resize:

                  @mathijsco

                  Isn`t this post the same as this one here (https://forum.qt.io/topic/105679/multiple-identical-qsliders-do-not-resize-properly-on-window-resize)?

                  Wow, it looks like a spambot just copied my post. That's not my account but it is my post (but partially).

                  I copied the code into an empty project to test it and it worked for me like it should.
                  Do you have any slots connected to your value-changed signal?

                  This code is all there is. No slots connected (if I do connect slots however, the problem persists). Could it be a mac specific issue? I encountered this issue first in a larger project with all kinds of other stuff in it. I created this small example to see if it was a Qt issue or something in my code. The small example showed the exact same problem so it does seem to be a Qt thing (at least on macOS).

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by kshegunov
                  #8

                  @mathijsco

                  Check out the answers below the "spambots" post :)
                  [Edit: Posts were moved into this thread. ~kshegunov]

                  @mrjj posted a bugreport link there, where your problem may refer to.

                  Please report the author of the other post.
                  Never seen a bot stealing / cloning random posts. Normally they try to sell something or post suspicious links :)


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  1 Reply Last reply
                  0
                  • mrjjM mrjj

                    Hi
                    This reminds me a bit of the posters having issues on MacOs with refresh
                    of widgets.
                    https://bugreports.qt.io/browse/QTBUG-68740
                    However, here in this post, it seems layout related so not sure its the same reason.

                    M Offline
                    M Offline
                    Mathijsco
                    wrote on last edited by
                    #9

                    @mrjj said in Multiple identical QSliders do not resize properly on window resize:

                    Hi
                    This reminds me a bit of the posters having issues on MacOs with refresh
                    of widgets.
                    https://bugreports.qt.io/browse/QTBUG-68740
                    However, here in this post, it seems layout related so not sure its the same reason.

                    That issue does seem to be fixed, though. Plus, I've only seen this issue with sliders and not with other widgets.
                    I decided to create a new bug report for this: https://bugreports.qt.io/projects/QTBUG/issues/QTBUG-77368

                    1 Reply Last reply
                    1

                    • Login

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