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. QSlider does not reach max or min

QSlider does not reach max or min

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 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.
  • F Offline
    F Offline
    Fabian727
    wrote on last edited by
    #1

    Hi guys,

    I create a new window by hand, because I use the QColorWheel, which is not compatible with the QT Creator Designer. ( I use QT 5.10)
    The window is created and I can use it. Only problem is, if I move the slider by hand, I can't reach the set maximum and minimum values (0 and 255). The changes are made visible in the QLine underneath. I also can change the value of the slider by this line. There it is possible to set the min/ max values, which are then accepted and realized on the slider.

    What do I need to reach the end of the slider/ min/max values by moving my mouse.

    thanks in advance,
    Fabian

    p.s.: here is the code for creating the slider

        /*reset the color to black*/
        activeColor.setAlpha(0);
        activeColor.setRed(0);
        activeColor.setGreen(0);
        activeColor.setBlue(0);
    
        /*set up the main window */
        QScreen *ratio = QGuiApplication::primaryScreen();
        window->setGeometry(ratio->geometry().width()-250,0,250,250);
        window->setFixedSize(250,250);
        window->setObjectName("ColorPicker");
    
        /* Graphical Objects */
        QWidget     *windowCentral    = new QWidget(window);
        QGridLayout *windowLayout     = new QGridLayout(windowCentral);
        windowColorWheel = new ColorWheel(window);
    
        windowWhiteSlider = new QSlider(window);
        windowWhiteSlider->setRange(0,255);
        windowWhiteSlider->setOrientation(Qt::Horizontal);
        windowWhiteSlider->setTickInterval(1);
        windowWhiteSlider->setSingleStep(1);
        windowWhiteSlider->setPageStep(10);
    
        windowLine = new QLineEdit(window);
        windowLine->setMaximumWidth(100);
    
        windowLayout->setObjectName("centralLayout");
        windowLayout->addWidget(windowColorWheel);
        windowLayout->addWidget(windowWhiteSlider);
        windowLayout->addWidget(windowLine);
    
        windowCentral->setLayout(windowLayout);
    
        window->setCentralWidget(windowCentral);
    
        /* Actions */
        windowActionQuit = new QAction(window);
        windowActionQuit->setShortcut(QKeySequence("Ctrl+Q"));
    
        windowActionClose = new QAction(window);
        windowActionClose->setShortcut(QKeySequence("Ctrl+W"));
    
        window->addAction(windowActionQuit);
        window->addAction(windowActionClose);
    
        /* window connections */
        connect(windowActionClose,SIGNAL(triggered()),window,SLOT(close()),Qt::DirectConnection);                    //close by Ctrl+W
    
        //colorwheel or slider changed, update the textline
        connect(windowColorWheel,SIGNAL(colorChanged(QColor)),window,SLOT(setLine(void)),Qt::DirectConnection);      //if color wheel is changed, change text line
        connect(windowWhiteSlider,SIGNAL(sliderMoved(int)),window,SLOT(setLine(void)),Qt::DirectConnection);
    
        //the textline was changed, update colorwheel and slider
        connect(windowLine,SIGNAL(editingFinished()),window,SLOT(setColor()),Qt::DirectConnection);
        connect(windowLine,SIGNAL(returnPressed()),window,SLOT(setColor()),Qt::DirectConnection);
    
    joeQJ 1 Reply Last reply
    0
    • F Fabian727

      Hi guys,

      I create a new window by hand, because I use the QColorWheel, which is not compatible with the QT Creator Designer. ( I use QT 5.10)
      The window is created and I can use it. Only problem is, if I move the slider by hand, I can't reach the set maximum and minimum values (0 and 255). The changes are made visible in the QLine underneath. I also can change the value of the slider by this line. There it is possible to set the min/ max values, which are then accepted and realized on the slider.

      What do I need to reach the end of the slider/ min/max values by moving my mouse.

      thanks in advance,
      Fabian

      p.s.: here is the code for creating the slider

          /*reset the color to black*/
          activeColor.setAlpha(0);
          activeColor.setRed(0);
          activeColor.setGreen(0);
          activeColor.setBlue(0);
      
          /*set up the main window */
          QScreen *ratio = QGuiApplication::primaryScreen();
          window->setGeometry(ratio->geometry().width()-250,0,250,250);
          window->setFixedSize(250,250);
          window->setObjectName("ColorPicker");
      
          /* Graphical Objects */
          QWidget     *windowCentral    = new QWidget(window);
          QGridLayout *windowLayout     = new QGridLayout(windowCentral);
          windowColorWheel = new ColorWheel(window);
      
          windowWhiteSlider = new QSlider(window);
          windowWhiteSlider->setRange(0,255);
          windowWhiteSlider->setOrientation(Qt::Horizontal);
          windowWhiteSlider->setTickInterval(1);
          windowWhiteSlider->setSingleStep(1);
          windowWhiteSlider->setPageStep(10);
      
          windowLine = new QLineEdit(window);
          windowLine->setMaximumWidth(100);
      
          windowLayout->setObjectName("centralLayout");
          windowLayout->addWidget(windowColorWheel);
          windowLayout->addWidget(windowWhiteSlider);
          windowLayout->addWidget(windowLine);
      
          windowCentral->setLayout(windowLayout);
      
          window->setCentralWidget(windowCentral);
      
          /* Actions */
          windowActionQuit = new QAction(window);
          windowActionQuit->setShortcut(QKeySequence("Ctrl+Q"));
      
          windowActionClose = new QAction(window);
          windowActionClose->setShortcut(QKeySequence("Ctrl+W"));
      
          window->addAction(windowActionQuit);
          window->addAction(windowActionClose);
      
          /* window connections */
          connect(windowActionClose,SIGNAL(triggered()),window,SLOT(close()),Qt::DirectConnection);                    //close by Ctrl+W
      
          //colorwheel or slider changed, update the textline
          connect(windowColorWheel,SIGNAL(colorChanged(QColor)),window,SLOT(setLine(void)),Qt::DirectConnection);      //if color wheel is changed, change text line
          connect(windowWhiteSlider,SIGNAL(sliderMoved(int)),window,SLOT(setLine(void)),Qt::DirectConnection);
      
          //the textline was changed, update colorwheel and slider
          connect(windowLine,SIGNAL(editingFinished()),window,SLOT(setColor()),Qt::DirectConnection);
          connect(windowLine,SIGNAL(returnPressed()),window,SLOT(setColor()),Qt::DirectConnection);
      
      joeQJ Offline
      joeQJ Offline
      joeQ
      wrote on last edited by
      #2

      @Fabian727 Hi, friend. Welcome.

      can you qDebug QSlider value in slot function of setLine, and why did you use void not int in slot function?

      connect(windowWhiteSlider,SIGNAL(sliderMoved(int)),window,SLOT(setLine(void)),Qt::DirectConnection);
      

      void -> int, and qDebug value in slot function.

      connect(windowWhiteSlider,SIGNAL(sliderMoved(int)),window,SLOT(setLine(int)),Qt::DirectConnection);
      

      Just do it!

      1 Reply Last reply
      5
      • A Offline
        A Offline
        ambershark
        wrote on last edited by
        #3

        I'm unable to duplicate your issue. I put this code together to test based on your creation of windowWhiteSlider and everything works fine. I can get to 0 and to 255 with the mouse.

        #include <QApplication>
        #include <QSlider>
        #include <QHBoxLayout>
        #include <QLabel>
        #include <QDebug>
        
        int main(int ac, char **av)
        {
                QApplication app(ac, av);
        
                auto window = new QWidget();
                window->resize(300,150);
        
            auto windowWhiteSlider = new QSlider(window);
            windowWhiteSlider->setRange(0,255);
            windowWhiteSlider->setOrientation(Qt::Horizontal);
            windowWhiteSlider->setTickInterval(1);
            windowWhiteSlider->setSingleStep(1);
            windowWhiteSlider->setPageStep(10);
                windowWhiteSlider->setValue(0);
        
                auto label = new QLabel(window);
                label->setText(QString::number(windowWhiteSlider->value()));
                QObject::connect(windowWhiteSlider, &QSlider::valueChanged, 
                                label, [=](int v) { label->setText(QString::number(v)); });
        
                auto layout = new QHBoxLayout();
                layout->addWidget(windowWhiteSlider);
                layout->addWidget(label);
                window->setLayout(layout);
        
                window->show();
        
                return app.exec();
        }
        

        Can you give us a video or a screenshot or more information on what the problem is? I was unable to duplicate it with what you shared.

        0_1526876718146_Screenshot from 2018-05-20 21-25-02.png

        0_1526876725239_Screenshot from 2018-05-20 21-25-05.png

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

        1 Reply Last reply
        4
        • M Offline
          M Offline
          Magge2k
          wrote on last edited by
          #4

          Hello,

          today i wanted to introduce a Slider which works from INT32_MAX to INT32_MIN.
          But this is not possible.

          Initial State with Limits => INT32_MAX, INT32_MIN
          a15ab944-6b0e-4720-95f4-4269f47ab5db-grafik.png

          When Clicking and Sliding
          652bc87d-6508-46bf-aef5-df8fc425886c-grafik.png

          After Release
          e90ba640-d4da-4ee3-bdd0-7a2e65efe326-grafik.png

          I found out that the Limit for a good Version Working is at INT32_MAX/2, INT32_MIN/2
          Initial
          681b8891-6c52-4be2-9cfd-1eac14ab38bc-grafik.png

          Lower Limit
          fc83a3d5-ccea-4442-b0ba-985ada86ca03-grafik.png

          Upper Limit
          474ca000-2967-4c3e-a161-3d9bf9b9dac0-grafik.png

          So my Question, is this a Bug or a Feature?

          I used Qt 5.15.2 with c++14.

          Thanks and Bye

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Since sliderPosition is only a signed int, the max range can also be max 2^31-1.
            A slider with such a huge range is useless since a user can never do a valid input then. Scale your slider values.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            3
            • M Offline
              M Offline
              Magge2k
              wrote on last edited by
              #6

              Ah OK, so internal Range is also signed int32 and not unsigned int32.

              The Scale Idea is a good workaround and you are right.
              But for quick random value setting i thought it would be easy just to use the value and define the maximum Limits.

              Christian EhrlicherC 1 Reply Last reply
              0
              • M Magge2k

                Ah OK, so internal Range is also signed int32 and not unsigned int32.

                The Scale Idea is a good workaround and you are right.
                But for quick random value setting i thought it would be easy just to use the value and define the maximum Limits.

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Magge2k said in QSlider does not reach max or min:

                Ah OK, so internal Range is also signed int32 and not unsigned int32.

                Yes: https://doc.qt.io/qt-5/qabstractslider.html#value-prop

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                0

                • Login

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