InBlock.gif#include <QApplication>
InBlock.gif#include <QHBoxLayout>
InBlock.gif#include <QSlider>
InBlock.gif#include <QSpinBox>
InBlock.gif#include <QLabel>
InBlock.gif#include <QObject>
InBlock.gif
InBlock.gif int 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(QObject::trUtf8( "输入你的年龄")); //标题显示:输入你的年龄
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(QObject::trUtf8( "你的年龄:"));
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
 
结果:
 
也可采用下面的:
InBlock.gif#include <QApplication>
InBlock.gif#include <QHBoxLayout>
InBlock.gif#include <QSlider>
InBlock.gif#include <QSpinBox>
InBlock.gif#include <QLabel>
InBlock.gif#include <QObject>
InBlock.gif#include <QTextCodec>
InBlock.gif
InBlock.gif int main( int argc, char *argv[])
InBlock.gif{    
InBlock.gif    QApplication app(argc, argv);
InBlock.gif
InBlock.gif     //设置tr的编码---这里是关键
InBlock.gif    QTextCodec::setCodecForTr(QTextCodec::codecForName( "UTF8"));    
InBlock.gif    
InBlock.gif    QWidget *window = new QWidget;
InBlock.gif    window->setWindowTitle(QObject::tr( "输入你的年龄")); //标题显示:输入你的年龄
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(QObject::tr( "你的年龄:"));
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
 
当然中日文混杂也是可以的: