qfedu-qt-level/qtdemo03/smallwidget.cpp

26 lines
655 B
C++
Raw Normal View History

#include "smallwidget.h"
SmallWidget::SmallWidget(QWidget *parent) : QWidget(parent)
{
spinBox = new QSpinBox(this);
spinBox->setGeometry(20,20,100,50);
slider = new QSlider(Qt::Vertical,this); // Horizontal 垂直方向
slider->setGeometry(140,20,40,100);
slider->setMaximum(100);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(spinBox);
layout->addWidget(slider);
setLayout(layout); // 设置当前 QWidget 的布局
connect(slider,&QSlider::valueChanged,[&](int val){
spinBox->setValue(val);
});
connect(spinBox, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
}