Laying out widgets 布局的使用 (三)
来源:互联网 发布:沙盒软件sandboxie 编辑:程序博客网 时间:2024/05/23 01:24
所有的widgets 都可以放到一个布局上进行自动布局
布局类有三个:
QHBoxLayout---- lays out widgets horizontally from left to right(right to left for some cultures)
QVBoxLayout---- lays out widgets vertically from top to bottom
QGridLayout---- lays out widgets in a grid
添加部件时 比如定义了几个部件,直接调用addWidget() 成员函数就可以
比如:
QSlider *slider=new QSlider // 滑动杆
QSpinBox *spin= new QSpinBox
QHBoxLayout *layout=new QHBoxLayout;
layout->addWidget(slider)
layout->addWidget(spin)
这样就把QSlider 和 QSpinBox 控件添加到了布局 layout这种
下面接着要做的就是把布局添加到窗口中
使用Widget::setLayout()
如:
QWidget *window=new QWidget;
window->setLayout(layout)
- 1 #include <QApplication>
- 2 #include <QHBoxLayout>
- 3 #include <QSlider>
- 4 #include <QSpinBox>
- 5 int main(int argc, char *argv[])
- 6 {
- 7 QApplication app(argc, argv);
- 8 QWidget *window = new QWidget;
- 9 window->setWindowTitle("Enter Your Age");
- 10 QSpinBox *spinBox = new QSpinBox;
- 11 QSlider *slider = new QSlider(Qt::Horizontal);
- 12 spinBox->setRange(0, 130);
- 13 slider->setRange(0, 130);
- 14 QObject::connect(spinBox, SIGNAL(valueChanged(int)),
- 15 slider, SLOT(setValue(int)));
- 16 QObject::connect(slider, SIGNAL(valueChanged(int)),
- 17 spinBox, SLOT(setValue(int)));
- 18 spinBox->setValue(35);
- 19 QHBoxLayout *layout = new QHBoxLayout;
- 20 layout->addWidget(spinBox);
- 21 layout->addWidget(slider);
- 22 window->setLayout(layout);
- 23 window->show();
- 24 return app.exec();
- 25 }
自己写的
- #include <QtGui/QApplication>
- #include "qt.h"
- #include <qpushbutton>
- #include<QHBoxLayout>
- #include <QSlider>
- #include<QSpinBox>
- int main(int argc, char *argv[])
- {
- QApplication app(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);
- QObject::connect(spinBox, SIGNAL(valueChanged(int)),
- slider, SLOT(setValue(int)));
- QObject::connect(slider, SIGNAL(valueChanged(int)),
- spinBox, SLOT(setValue(int)));
- spinBox->setValue(35);
- QHBoxLayout *layout = new QHBoxLayout;
- layout->addWidget(spinBox);
- layout->addWidget(slider);
- window->setLayout(layout);
- window->show();
- return app.exec();
- }
- Laying out widgets 布局的使用 (三)
- Laying Out Widgets
- 6-1 排列窗体上的控件(Laying Out Widgets on a Form)
- 1.3控件的几何排列-Laying Out Widgets
- 1.3控件的几何排列-Laying Out Widgets
- 【C1】基本学习【S3】Laying Out Widgets
- Qt之Laying Out Widgets篇【linux window 平台】
- android---widgets的使用
- App Widgets的使用
- Laying out text with Core Text
- Laying out text with Core Text
- 使用Lay Out里面的VFL实现自动布局
- jQuery UI -- widgets各种部件的使用
- GYM 100971 D.Laying Cables(set)
- CFgym: Laying Cables(单调栈)
- Widgets高级篇(三)
- Widgets高级篇(三)
- RecyclerView的使用(三)多布局
- dbgrid的重画功能
- 网站天气预报连接代码
- GridView格式化导出Excel收藏
- GridView表头编辑
- 在Linux下安装MPlayer的全过程
- Laying out widgets 布局的使用 (三)
- gridveiw操作大全
- HClean垃圾清理软件
- 32道经典java面试题
- gridview大全(2)
- Hadoop学习笔记一 简要介绍
- .net的DateTime加上一段时间
- Hadoop学习笔记二 安装部署
- gridview跨行计算