#include <QApplication>
#include <QtGui>
int main(int argc,char * argv[])
{
QApplication app(argc,argv);
QWidget * window = new QWidget;
window->setWindowTitle("Enter your age");
QSpinBox * spinBox = new QSpinBox;
spinBox->setRange(0,300);
QSlider * slider = new QSlider(Qt::Vertical);
slider->setRange(0,300);
QSlider * slider1 = new QSlider(Qt::Horizontal);
slider1->setRange(0,300);
QObject::connect(slider,SIGNAL(valueChanged(int)),spinBox,SLOT(setValue(int)));
QObject::connect(spinBox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
QObject::connect(slider1,SIGNAL(valueChanged(int)),spinBox,SLOT(setValue(int)));
QObject::connect(spinBox,SIGNAL(valueChanged(int)),slider1,SLOT(setValue(int)));
QObject::connect(slider1,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
QObject::connect(slider,SIGNAL(valueChanged(int)),slider1,SLOT(setValue(int)));
spinBox->setValue(55);
QHBoxLayout * layout = new QHBoxLayout;
layout->addWidget(spinBox);
layout->addWidget(slider);
layout->addWidget(slider1);
window->setLayout(layout);
window->show();
return app.exec();
}qt,spinbox slider
最新推荐文章于 2025-09-28 10:45:13 发布
本文通过一个Qt应用程序示例介绍了如何使用QSpinBox和QSlider,并实现它们之间的双向数据同步。具体实现了当其中一个控件的值发生变化时,其它控件的值也会相应更新。
1669

被折叠的 条评论
为什么被折叠?



