Dr.Wing

心翼的技术笔记本

  :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
 1 #include<QApplication>
2 #include<QHBoxLayout>
3 #include<QSpinBox>
4 #include<QSlider>
5
6 int main(int argc,char* argv[])
7 {
8 QApplication app(argc,argv); //创建app的构造函数
9 QWidget* window = new QWidget; //new一个window
10 window->setWindowTitle("Set the value"); //设置caption
11
12 QSpinBox* spinbox = new QSpinBox; //new一个spinbox
13 QSlider* slider = new QSlider(Qt::Horizontal); //new一个slider
14
15 spinbox->setRange(0,150); //设置范围,->符号
16 slider->setRange(0,150);
17
18 QObject::connect(spinbox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
19 QObject::connect(slider,SIGNAL(valueChanged(int)),spinbox,SLOT(setValue(int)));
20
21 //信号和槽,(发送者,信号,接收者,槽).第一个是spinbox发送给slider的
22 //第二个是slider发送给spinbox的
23 spinbox->setValue(28);
24
25 //QHBoxLayout是布局管理器,即在水平方向上排列窗口部件
26 QHBoxLayout* layout = new QHBoxLayout;
27 layout->addWidget(spinbox);
28 layout->addWidget(slider);
29 window->setLayout(layout);
30
31 window->show(); //窗体显示
32 return app.exec();
33 }
要注意:一共有三种布局管理器
① QHBoxLayout  //水平方向布局管理器
② VHBoxLayout  //竖直方向布局管理器
③ QGridLayout  //把每个窗口部件排列在一个网格中
posted on 2012-03-20 15:55  心翼  阅读(1102)  评论(0编辑  收藏  举报