morgancodes
morgancodes

Reputation: 25265

Why does updating one QSlider set the value of another QSlider?

#include <QtWidgets>
#include <QtCore>
#include <QtGui>
#include <iostream>
    
int main(int argc, char *argv[]) {
    QApplication  app(argc, argv);
    {
        auto w = new QWidget();
        
        QSlider *verticalSlider;
        QSlider *verticalSlider_2;
        
        verticalSlider = new QSlider(w);
        verticalSlider->setGeometry(QRect(70, 70, 22, 160));
        verticalSlider->setOrientation(Qt::Vertical);
        verticalSlider_2 = new QSlider(w);
        verticalSlider_2->setGeometry(QRect(140, 70, 22, 160));
        verticalSlider_2->setOrientation(Qt::Vertical);
        
        w->show();
    }
    
    return app.exec();
}

When I slide verticalSlider to a different value, then switch focus to a different window, verticalSlider_2 gets set to the value of verticalSlider.

If I switch the orientation of verticalSlider_2 to Qt::Horizontal, the sliders are able to move independently.

Demonstration GIF


I'm using:

Upvotes: 0

Views: 50

Answers (0)

Related Questions