Qt里的spin控件_GUI#include <QApplication>
Qt里的spin控件_GUI#include <QHBoxLayout>
Qt里的spin控件_GUI#include <QSlider>
Qt里的spin控件_GUI#include <QSpinBox>
Qt里的spin控件_GUI#include <QLabel>
Qt里的spin控件_GUI
Qt里的spin控件_GUIint main(int argc, char *argv[])
Qt里的spin控件_GUI{    
Qt里的spin控件_GUI    QApplication app(argc, argv);
Qt里的spin控件_GUI
Qt里的spin控件_GUI    QWidget *window = new QWidget;
Qt里的spin控件_GUI    window->setWindowTitle("Enter Your Age");//标题显示:输入你的年龄
Qt里的spin控件_GUI
Qt里的spin控件_GUI    QSpinBox *spinBox = new QSpinBox;
Qt里的spin控件_GUI    QSlider *slider = new QSlider(Qt::Horizontal);//滑块组件
Qt里的spin控件_GUI    spinBox->setRange(0, 130);//设置各自的取值范围
Qt里的spin控件_GUI    slider->setRange(0, 130);
Qt里的spin控件_GUI
Qt里的spin控件_GUI    //滑块和Spin组件的值的变化都会对应的改变
Qt里的spin控件_GUI    QObject::connect(spinBox, SIGNAL(valueChanged(int)),
Qt里的spin控件_GUI                                     slider, SLOT(setValue(int)));
Qt里的spin控件_GUI    QObject::connect(slider, SIGNAL(valueChanged(int)),
Qt里的spin控件_GUI                                     spinBox, SLOT(setValue(int)));
Qt里的spin控件_GUI                                        
Qt里的spin控件_GUI    spinBox->setValue(35);//注意这里的设置也会影响slider
Qt里的spin控件_GUI
Qt里的spin控件_GUI    QHBoxLayout *layout = new QHBoxLayout;
Qt里的spin控件_GUI    layout->addWidget(spinBox);
Qt里的spin控件_GUI    layout->addWidget(slider);
Qt里的spin控件_GUI    
Qt里的spin控件_GUI    QLabel* label=new QLabel("your age:");
Qt里的spin控件_GUI    
Qt里的spin控件_GUI    QVBoxLayout* mainLayout=new QVBoxLayout;
Qt里的spin控件_GUI    mainLayout->addWidget(label);
Qt里的spin控件_GUI    mainLayout->addLayout(layout);
Qt里的spin控件_GUI    
Qt里的spin控件_GUI    window->setLayout(mainLayout);
Qt里的spin控件_GUI
Qt里的spin控件_GUI    window->resize(300,50);
Qt里的spin控件_GUI    window->show();
Qt里的spin控件_GUI
Qt里的spin控件_GUI    return app.exec();
Qt里的spin控件_GUI}    
Qt里的spin控件_GUI
 
截图:
Qt里的spin控件_GUI_45