Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSlider does not reach max or min



  • 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);
    


  • @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);
    

  • Moderators

    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


Log in to reply