Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. QSlider inside layout, update on resize.
QtWS25 Last Chance

QSlider inside layout, update on resize.

Scheduled Pinned Locked Moved Unsolved Brainstorm
11 Posts 3 Posters 3.7k 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.
  • L Offline
    L Offline
    Lezginohohol
    wrote on 24 May 2019, 13:35 last edited by
    #1

    when resizing window Q slider widget keeps its size and is not adjusted to new window size.
    I've tried:
    setTracking()
    adjustSize()
    update()
    updateGeometry()

    similar behavior i found in "chip" example project when you resize window or move splitters zoomSlider and RotateSlider will not change their scale. I need click slider or buttons to have it adjusted to new size.
    here you can see chip after resize:
    0_1558704701007_7961a27f-d1d1-42b8-a8b9-2c476993948a-image.png
    both of sliders kept their old sizes.
    i think problem is in nesting: slider is in layout -> layout is in widget -> widget in window.
    when slider is in window i don't face any problem.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 24 May 2019, 19:08 last edited by
      #2

      Hi and welcome to devnet,

      What version of Qt are you using ?
      What OS are you running ?
      Can you provide a minimal compilable example that shows that behaviour ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply 25 May 2019, 22:18
      0
      • P Offline
        P Offline
        Pradeep P N
        wrote on 25 May 2019, 14:06 last edited by
        #3

        Hi @Lezginohohol
        Did you try this ?
        https://doc.qt.io/qt-5/qwidget.html#resizeEvent

        void QWidget::resizeEvent(QResizeEvent *event)
        

        below is sample code for the QSlider on resizeEvent of widget class.

        Widget::Widget(QWidget *parent)
            : QWidget(parent)
            , m_Slider(new QSlider(Qt::Horizontal, this))
        {
        }
        
        void Widget::resizeEvent(QResizeEvent *event)
        {
            qDebug() << event->size() << endl;
            // Please add the width as per your requirement in place of 20.
            m_Slider->resize(event->size().width(), 20);
        }
        

        Output :
        0_1558793192082_2ff43d86-6e32-4c09-8b84-b588797a7e52-image.png

        0_1558793134226_27906b54-5b00-4e8d-91b5-c88703a5b8fe-image.png

        All the best, have a great day.

        Pradeep Nimbalkar.
        Upvote the answer(s) that helped you to solve the issue...
        Keep code clean.

        L 1 Reply Last reply 25 May 2019, 22:29
        2
        • S SGaist
          24 May 2019, 19:08

          Hi and welcome to devnet,

          What version of Qt are you using ?
          What OS are you running ?
          Can you provide a minimal compilable example that shows that behaviour ?

          L Offline
          L Offline
          Lezginohohol
          wrote on 25 May 2019, 22:18 last edited by Lezginohohol
          #4

          @SGaist
          Hi.

          Sorry for late answer. I was offline whole day.
          Os - macOS Mojave 10.14.4

          Qt 5.12.1

          XCode 10.2.1

          and I checked "chip" example on Windows 10 and planning to check on Ubuntu.
          At Windows it is ok. sliders working correctly.

          1 Reply Last reply
          0
          • P Pradeep P N
            25 May 2019, 14:06

            Hi @Lezginohohol
            Did you try this ?
            https://doc.qt.io/qt-5/qwidget.html#resizeEvent

            void QWidget::resizeEvent(QResizeEvent *event)
            

            below is sample code for the QSlider on resizeEvent of widget class.

            Widget::Widget(QWidget *parent)
                : QWidget(parent)
                , m_Slider(new QSlider(Qt::Horizontal, this))
            {
            }
            
            void Widget::resizeEvent(QResizeEvent *event)
            {
                qDebug() << event->size() << endl;
                // Please add the width as per your requirement in place of 20.
                m_Slider->resize(event->size().width(), 20);
            }
            

            Output :
            0_1558793192082_2ff43d86-6e32-4c09-8b84-b588797a7e52-image.png

            0_1558793134226_27906b54-5b00-4e8d-91b5-c88703a5b8fe-image.png

            All the best, have a great day.

            L Offline
            L Offline
            Lezginohohol
            wrote on 25 May 2019, 22:29 last edited by
            #5

            @Pradeep-P-N said in QSlider inside layout, update on resize.:

            https://doc.qt.io/qt-5/qwidget.html#resizeEvent

            Hi. I know this. but my Slider is in layout. with buttons at top and bottom. when slider is single - it is working correctly.
            and buttons are not class fields. they created, added to widget, connected where needed.
            Now i am working with children() of main widget (where i implemented resize) and trying to locate QSlider object in it.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 25 May 2019, 22:32 last edited by
              #6

              Do you mean that the example also has that issue ?

              If not, then again, please provide a minimal example that shows it.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              L 1 Reply Last reply 25 May 2019, 22:57
              0
              • S SGaist
                25 May 2019, 22:32

                Do you mean that the example also has that issue ?

                If not, then again, please provide a minimal example that shows it.

                L Offline
                L Offline
                Lezginohohol
                wrote on 25 May 2019, 22:57 last edited by
                #7

                example "chip"
                https://doc.qt.io/qt-5/qtwidgets-graphicsview-chip-example.html
                picture i provided in post is this example.
                zoomSlider and rotateSlider are defined in class View extending QFrame.
                And in debugger they are getting new size, but elements inside slider widget are not resized.
                As i said this happens only at macOS. Windows - ok, Ubuntu not checked.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 26 May 2019, 21:13 last edited by SGaist
                  #8

                  The chip example works properly here with Qt 5.12.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Pradeep P N
                    wrote on 27 May 2019, 03:10 last edited by Pradeep P N
                    #9

                    Hi @Lezginohohol

                    Below is sample code using Layout and Buttons And this works without resizeEvent for the Widget. Let me know if anything is missing.

                    Widget::Widget(QWidget *parent)
                        : QWidget(parent)
                        , m_Slider(new QSlider(Qt::Horizontal))
                        , m_Button1(new QPushButton("1"))
                        , m_Button2(new QPushButton("2"))
                        , m_VBLayout(new QVBoxLayout)
                    {
                    
                        m_VBLayout->addWidget(m_Button1);
                        m_VBLayout->addWidget(m_Slider);
                        m_VBLayout->addWidget(m_Button2);
                    
                        this->setLayout(m_VBLayout);
                    
                    }
                    

                    0_1558928586966_slider.gif

                    The Chip example also works fine Qt 5.12.2

                    0_1558926911818_QtChip.gif

                    Pradeep Nimbalkar.
                    Upvote the answer(s) that helped you to solve the issue...
                    Keep code clean.

                    L 1 Reply Last reply 27 May 2019, 06:19
                    2
                    • P Pradeep P N
                      27 May 2019, 03:10

                      Hi @Lezginohohol

                      Below is sample code using Layout and Buttons And this works without resizeEvent for the Widget. Let me know if anything is missing.

                      Widget::Widget(QWidget *parent)
                          : QWidget(parent)
                          , m_Slider(new QSlider(Qt::Horizontal))
                          , m_Button1(new QPushButton("1"))
                          , m_Button2(new QPushButton("2"))
                          , m_VBLayout(new QVBoxLayout)
                      {
                      
                          m_VBLayout->addWidget(m_Button1);
                          m_VBLayout->addWidget(m_Slider);
                          m_VBLayout->addWidget(m_Button2);
                      
                          this->setLayout(m_VBLayout);
                      
                      }
                      

                      0_1558928586966_slider.gif

                      The Chip example also works fine Qt 5.12.2

                      0_1558926911818_QtChip.gif

                      L Offline
                      L Offline
                      Lezginohohol
                      wrote on 27 May 2019, 06:19 last edited by
                      #10

                      @Pradeep-P-N
                      Ok, then i will search problem in my macOS and Qt installation

                      P 1 Reply Last reply 27 May 2019, 06:30
                      0
                      • L Lezginohohol
                        27 May 2019, 06:19

                        @Pradeep-P-N
                        Ok, then i will search problem in my macOS and Qt installation

                        P Offline
                        P Offline
                        Pradeep P N
                        wrote on 27 May 2019, 06:30 last edited by Pradeep P N
                        #11

                        @Lezginohohol
                        Did you try the sample code in macOS ?

                        I did test on Windows, Ubuntu & macOS.
                        It works fine.

                        Pradeep Nimbalkar.
                        Upvote the answer(s) that helped you to solve the issue...
                        Keep code clean.

                        1 Reply Last reply
                        1

                        2/11

                        24 May 2019, 19:08

                        topic:navigator.unread, 9
                        • Login

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