#include <QtGui/QApplication>
#include <QtGui/QWidget>
#include <QtGui/QSpinBox>
#include <QtGui/QSlider>
#include <QtGui/QHBoxLayout>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window = new QWidget; //首先创建了一个QWidget的实例
window->setWindowTitle("Enter your age");//调用setWindowTitle函数来设置窗口标题
QSpinBox *spinBox = new QSpinBox; //然后创建了一个QSpinBox和QSlider
QSlider *slider = new QSlider(Qt::Horizontal);
spinBox->setRange(0, 130); //分别设置了它们值的范围,使用的是setRange函数
slider->setRange(0, 130);
QObject::connect(slider, SIGNAL(valueChanged(int)), spinBox, SLOT(setValue(int)));
QObject::connect(spinBox, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
spinBox->setValue(35);
QHBoxLayout *layout = new QHBoxLayout;//然后是一个QHBoxLayout,就是一个水平布局,按照从左到右的顺序进行添加
layout->addWidget(spinBox); //使用addWidget添加好组件
layout->addWidget(slider);
window->setLayout(layout); //调用QWidget的setLayout把QWidget的layout设置为我们定义的这个Layout
window->show();
return app.exec();
}
//