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. How one QSlider move the other 3 QSliders ?

How one QSlider move the other 3 QSliders ?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.3k 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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1

    The top QSlider move other QSliders below.
    替代文字

    https://github.com/sonichy

    Pl45m4P 1 Reply Last reply
    0
    • sonichyS sonichy

      The top QSlider move other QSliders below.
      替代文字

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

      @sonichy

      You have to set how exactly the other Sliders gonna move, when your RBG-Slider was moved, but in general something like this should work:

      connect(slider_rgb, &QSlider::valueChanged, this, &QDialog::calcSliderVal); // Connect to a slot where you calculate and set the value of the other sliders
      
      

      If you want to move them in the same way as the RGB slider (which makes no sense in your case), you just connect the valueChanged(int val)-Signal to the setValue(int val)- slot


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

      ~E. W. Dijkstra

      sonichyS 1 Reply Last reply
      4
      • Pl45m4P Pl45m4

        @sonichy

        You have to set how exactly the other Sliders gonna move, when your RBG-Slider was moved, but in general something like this should work:

        connect(slider_rgb, &QSlider::valueChanged, this, &QDialog::calcSliderVal); // Connect to a slot where you calculate and set the value of the other sliders
        
        

        If you want to move them in the same way as the RGB slider (which makes no sense in your case), you just connect the valueChanged(int val)-Signal to the setValue(int val)- slot

        sonichyS Offline
        sonichyS Offline
        sonichy
        wrote on last edited by
        #3

        @pl45m4 The problem is how to get old value before change in QSlider::valueChanged signal, then calculate the difference value.

        https://github.com/sonichy

        Pl45m4P 1 Reply Last reply
        0
        • sonichyS sonichy

          @pl45m4 The problem is how to get old value before change in QSlider::valueChanged signal, then calculate the difference value.

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

          @sonichy

          One possible way is to store the current slider value in a member var and take this value as reference when the value changes.

          Or you try this: https://doc.qt.io/qt-5/qabstractslider.html#actionTriggered
          This signal is emitted, whenever the slider changes (not the value).
          There is also this (https://doc.qt.io/qt-5/qabstractslider.html#sliderMoved) but it only gets emitted when you move the slider with your mouse, not when the slider moves by using the keyboard.


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

          ~E. W. Dijkstra

          sonichyS 1 Reply Last reply
          3
          • Pl45m4P Pl45m4

            @sonichy

            One possible way is to store the current slider value in a member var and take this value as reference when the value changes.

            Or you try this: https://doc.qt.io/qt-5/qabstractslider.html#actionTriggered
            This signal is emitted, whenever the slider changes (not the value).
            There is also this (https://doc.qt.io/qt-5/qabstractslider.html#sliderMoved) but it only gets emitted when you move the slider with your mouse, not when the slider moves by using the keyboard.

            sonichyS Offline
            sonichyS Offline
            sonichy
            wrote on last edited by
            #5

            @pl45m4 OK, actionTriggered is the signal before move !

            int ov = 0;
            connect(slider, &QSlider::actionTriggered, [&](){
                ov = slider->value();
            });
            connect(slider, &QSlider::valueChanged, [&](int v){
                sliderR->setValue(sliderR->value() + v - ov);
                sliderG->setValue(sliderG->value() + v - ov);
                sliderB->setValue(sliderB->value() + v - ov);
            });
            

            https://github.com/sonichy

            1 Reply Last reply
            2

            • Login

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