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. Vertical slider again

Vertical slider again

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

    Hello,

    My topic is mark as solved but i got a new error :

    i have :

    Hello guys,

    i want to use a vertical slider to increase a variable

    void MainWindow::on_verticalSlider_sliderMoved(int position)
    {
        ui->verticalSlider->setRange(1,50);
    z++;
    }
    

    but as i didn't expected, is that whenever the slider moove he will increment the variable z.

    But i want that the slider decrease the variable z when he go down.
    and increase when he go up !

    thanks for your help

    A 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean you want z to have the same value as the slider ?

      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
        Payx
        wrote on last edited by
        #3

        Yes exactly

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then it's simply: z = position;

          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
          1
          • P Payx

            Hello,

            My topic is mark as solved but i got a new error :

            i have :

            Hello guys,

            i want to use a vertical slider to increase a variable

            void MainWindow::on_verticalSlider_sliderMoved(int position)
            {
                ui->verticalSlider->setRange(1,50);
            z++;
            }
            

            but as i didn't expected, is that whenever the slider moove he will increment the variable z.

            But i want that the slider decrease the variable z when he go down.
            and increase when he go up !

            thanks for your help

            A Offline
            A Offline
            ambershark
            wrote on last edited by ambershark
            #5

            void MainWindow::on_verticalSlider_sliderMoved(int position)
            {
            ui->verticalSlider->setRange(1,50);
            z++;
            }

            Well you definitely don't need to call setRange more than once on a slider. So remove that line.

            Then what you need is:

            void MainWindow::on_verticalSlider_sliderMoved(int position)
            {
               z = position;
            }
            

            Edit: @SGaist beat me to it. ;)

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            1
            • P Offline
              P Offline
              Payx
              wrote on last edited by
              #6

              Thank you,

              but i don't need a number for my "z" ?
              How do we know the number of my variable ?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                What exactly do you want to do with z ?

                What is your goals ?

                That would help us understand what you are trying to achieve.

                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
                  Payx
                  wrote on last edited by
                  #8

                  I have a slider who determine the value of "z"

                  i thought use a setrange for the slider (1 to 50)

                  Like if the vertical slider is at the bottom, the value of z will be 1
                  and if the slider is at the top the value of z will be 50

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Call setRange in your MainWindow constructor.

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

                      Call SetRange ? i don't undertsand

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        That line: ui->verticalSlider->setRange(1,50); you should call it in the MainWindow constructor.

                        And since you are using a Designer based interface you can also set the min and max values in Designer and avoid the setRange call.

                        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
                          Payx
                          wrote on last edited by Payx
                          #12

                          So the z=position;
                          i keep it ?

                          Sorry but even the "main constructor" it's the .cpp ? or .h ?

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            Well... Yes if you use it somewhere else.

                            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
                              Payx
                              wrote on last edited by
                              #14

                              Yes i use the z somewhere else

                              thats why i needed a range 1 - 50

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                Where exactly ? Depending on that, there's not even a need for z. You can get the value directly from the slider.

                                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
                                  Payx
                                  wrote on last edited by
                                  #16

                                  It depends where i use my "z" ?

                                  How ?

                                  A 1 Reply Last reply
                                  0
                                  • P Offline
                                    P Offline
                                    Payx
                                    wrote on last edited by
                                    #17

                                    thank's anyway,

                                    3 h on it, i had time to ask help

                                    1 Reply Last reply
                                    0
                                    • P Payx

                                      It depends where i use my "z" ?

                                      How ?

                                      A Offline
                                      A Offline
                                      ambershark
                                      wrote on last edited by
                                      #18

                                      @Payx said in Vertical slider again:

                                      It depends where i use my "z" ?

                                      How ?

                                      What do you use z for? Also side note, that's a horrible name for a variable locally much less one that is used at a class or global level.

                                      What @SGaist is saying is you can always get the value of the slider from the slider itself without saving it to a variable. The function ui->verticalSlider->sliderPosition() will always contain the same value that your z would.

                                      So with that in mind you can get rid of that whole overridden function and just call sliderPosition() when you need the value.

                                      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                                      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