2

I'm using mostly double spin boxes in my application and I'm connecting each one to a slider to sync up their values.

The method I'm using works perfectly except when the spin box value reaches 0.28, 0.56, and 1.12. When using my scroll wheel to change the slider and spin box or the spin box buttons, it gets stuck on one or all of these values and won't advance any further.

I've made a sample application with just one slider and a double spin box that exhibits the same behavior.

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->horizontalSlider, &QSlider::valueChanged, [=]() {emit changeSpinBoxValWithSliderVal(ui->horizontalSlider->value(), 0.01, "doubleSpinBox");});
    connect(ui->doubleSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=](double) {emit changeSliderValWithSpinBoxVal(ui->doubleSpinBox->value(), 100, "horizontalSlider");});
}
void MainWindow::changeSpinBoxValWithSliderVal(int sliderValue, double stepSize, QString spinBoxName)
{
    MainWindow::findChild<QDoubleSpinBox*>(spinBoxName)->setValue(double(sliderValue*stepSize));
}

void MainWindow::changeSliderValWithSpinBoxVal(double spinBoxValue, int multiplier, QString sliderName)
{
    MainWindow::findChild<QSlider*>(sliderName)->setValue(int(spinBoxValue*multiplier));
}
MainWindow::~MainWindow()
{
    delete ui;
}

QSlider range: 0-200

QSlider step size: 1

QDoubleSpinbox range: 0.00-2.00

QDoubleSpinbox step size: 0.01

spin box attributes

slider attributes

NoobN3rd
  • 1,223
  • 1
  • 9
  • 19
  • 1
    Just tried your example and I got the same error. I'm simply holding down the 'up arrow' button on the Double Spin box. What I get is that when I reach 1.12 the value does exaclty the following: 1.12, 1.13, 1.14 and then return to 1,12 in a continuous loop. I suppose it is a Qt bug. Which version of Qt are you using? – Salvo May 29 '20 at 07:10

0 Answers0