您的位置:首页 > 编程语言 > Qt开发

qt窗口部件的布局

2015-10-15 14:15 537 查看
//读书笔记:

#include "qt0.h"

#include<QApplication>

#include<QHBoxLayout>

#include<QSlider>

#include<QSpinBox>

int main(int argc, char *argv[])

{
QApplication a(argc, argv);
QWidget * window = new QWidget;
//设置窗口标题栏文字
window->setWindowTitle("Enter Your Age");
//微调框
QSpinBox * spinBox = new QSpinBox;
//滑块
QSlider *slider = new QSlider(Qt::Horizontal);
spinBox->setRange(0,130);
slider->setRange(0,130);
//connect参数:发射信号的窗口部件,信号(调用函数),接收信号的窗口部件,信号(接收函数))
QObject::connect(spinBox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
QObject::connect(slider,SIGNAL(valueChanged(int)),spinBox,SLOT(setValue(int)));
spinBox->setValue(35);
//布局管理器:一个能够对其所负责窗口部件的尺寸大小和位置进行设置的对象
//QT有三个主要的布局管理器:
//QHBoxLayout:在水平方向上排列窗口部件,从左到右
//QVBoxLayout:在竖直方向上排列窗口部件,从上到下
//QGridLayout:把各个窗口部件排列在一个网格中
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(spinBox);
layout->addWidget(slider);
window->setLayout(layout);
window->show();
return a.exec();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  读书笔记 qt