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