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.

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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on 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
    0
    • Pradeep P NP Offline
      Pradeep P NP Offline
      Pradeep P N
      wrote on 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
      2
      • SGaistS SGaist

        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 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
        • Pradeep P NP Pradeep P N

          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 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
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on 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
            0
            • SGaistS SGaist

              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 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
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on 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
                • Pradeep P NP Offline
                  Pradeep P NP Offline
                  Pradeep P N
                  wrote on 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
                  2
                  • Pradeep P NP Pradeep P N

                    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 last edited by
                    #10

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

                    Pradeep P NP 1 Reply Last reply
                    0
                    • L Lezginohohol

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

                      Pradeep P NP Offline
                      Pradeep P NP Offline
                      Pradeep P N
                      wrote on 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

                      • Login

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