#define RULER_RATIO 100.0f const int nMin = 10; const int nMax = 3000; const double dSingleStep = 0.01; QDoubleSpinBox *zoomSpinBox = new QDoubleSpinBox(this); zoomSpinBox->setRange(nMin / RULER_RATIO, nMax / RULER_RATIO); zoomSpinBox->setSingleStep(dSingleStep); //步长 zoomSpinBox->setDecimals(2); //两位小数 QSlider *zoomSlider = new QSlider(this); zoomSlider->setRange(nMin, nMax); //刻度滑块大小的取值范围;与宏定义RULER_RATIO紧密相连 zoomSlider->setValue(RULER_RATIO); zoomSlider->setFixedWidth(200); zoomSlider->setToolTip(tr("调整帧的宽度")); zoomSlider->setOrientation(Qt::Horizontal); zoomSlider->setFocusPolicy(Qt::TabFocus); //信号槽相互改变 //如果微调框是int型 //connect(zoomSpinBox, SIGNAL(valueChanged(int)), zoomSlider, SLOT(setValue(int))); //connect(zoomSlider, SIGNAL(valueChanged(int)), zoomSpinBox, SLOT(setValue(int))); //如果微调框是double型 connect(zoomSpinBox, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), zoomSlider, [=](double v) { zoomSlider->setValue(v * RULER_RATIO); }); connect(zoomSpinBox, static_cast<void(QDoubleSpinBox::*)(const QString &)>(&QDoubleSpinBox::valueChanged), zoomSlider, [=](const QString &text) { //double d = zoomSpinBox->valueFromText(text); //小数转QString,保留2位小数 //QString str = QString::number(d, 'f', 2); }); //滑块 connect(zoomSlider, &QSlider::valueChanged, mTracks, &TimeLineCells::setFrameSize); connect(zoomSlider, &QSlider::valueChanged, this, [=](int v) { zoomSpinBox->setValue(v / RULER_RATIO); });