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

44 Views Asked by At
#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

  • Why is the second slider being set to the same position as the first?
  • What do I need to do so the sliders of the same orientation can move independently?

I'm using:

  • MacOS 12.6 (Monterey)
  • Qt 5.15.2
0

There are 0 best solutions below