qt学习笔记可扩展对话框
来源:互联网 发布:人人贷网络借贷平台 编辑:程序博客网 时间:2024/05/18 00:38
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
设置窗体的大小固定,不能经过拖动改变大小
extension.h#ifndef EXTENSION_H#define EXTENSION_H#include <QDialog>#include <QLabel>#include <QLineEdit>#include <QPushButton>#include <QComboBox>#include <QGridLayout>class Extension : public QDialog{ Q_OBJECTpublic: Extension(QWidget *parent = 0); ~Extension(); void createBaseWidget(); void createDetailWidget();private: QWidget *baseWidget; QWidget *detailWidget; /* base */ QLabel *nameLabel; QLabel *sexLabel; QLineEdit *nameLineEdit; QComboBox *sexComBox; QPushButton *okBtn; QPushButton *detailBtn; /* detail */ QLabel *ageLabel; QLineEdit *ageLineEdit; QLabel *departmentLabel; QComboBox *departmentComboBox; QLabel *emailLabel; QLineEdit *emailLineEdit;private slots: void slotExtension();};#endif // EXTENSION_H
extension.cpp#include "extension.h"Extension::Extension(QWidget *parent) : QDialog(parent){ createBaseWidget(); createDetailWidget(); setWindowTitle(tr("可扩展对话框")); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(baseWidget); mainLayout->addWidget(detailWidget); mainLayout->setSizeConstraint(QLayout::SetFixedSize); this->setLayout(mainLayout); connect(detailBtn, SIGNAL(clicked()), this, SLOT(slotExtension()));}void Extension::createBaseWidget(){ nameLabel = new QLabel(tr("姓名")); nameLineEdit = new QLineEdit; okBtn = new QPushButton(tr("确定")); sexLabel = new QLabel(tr("性别")); sexComBox = new QComboBox; sexComBox->addItem(tr("男")); sexComBox->addItem(tr("女")); detailBtn = new QPushButton(tr("详细")); QGridLayout *baseLayout = new QGridLayout; baseLayout->addWidget(nameLabel, 0, 0); baseLayout->addWidget(nameLineEdit, 0, 1); baseLayout->addWidget(okBtn, 0, 2); baseLayout->addWidget(sexLabel, 1, 0); baseLayout->addWidget(sexComBox, 1, 1); baseLayout->addWidget(detailBtn, 1, 2); baseWidget = new QWidget; baseWidget->setLayout(baseLayout);}void Extension::createDetailWidget(){ ageLabel = new QLabel(tr("姓名")); ageLineEdit = new QLineEdit; departmentLabel = new QLabel(tr("部门")); departmentComboBox = new QComboBox; departmentComboBox->addItem(tr("部门1")); departmentComboBox->addItem(tr("部门2")); departmentComboBox->addItem(tr("部门3")); emailLabel = new QLabel(tr("email")); emailLineEdit = new QLineEdit; QGridLayout *detailLayout = new QGridLayout; detailLayout->addWidget(ageLabel, 0, 0); detailLayout->addWidget(ageLineEdit, 0, 1); detailLayout->addWidget(departmentLabel, 1, 0); detailLayout->addWidget(departmentComboBox, 1, 1); detailLayout->addWidget(emailLabel, 2, 0); detailLayout->addWidget(emailLineEdit, 2, 1); detailWidget = new QWidget; detailWidget->setLayout(detailLayout);}void Extension::slotExtension(){ if(detailWidget->isHidden()) detailWidget->show(); else detailWidget->hide();}Extension::~Extension(){}
main.cpp
include “extension.h”
include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Extension w;
w.show();
return a.exec();
}
2 0
- qt学习笔记可扩展对话框
- QT学习 之 对话框 (一) 可扩展对话框
- Qt 实现可扩展对话框
- Qt 实现可扩展对话框
- Qt 可扩展对话框创建--实验
- Qt:可扩展对话框的实现
- qt学习之扩展对话框
- Qt学习笔记--对话框
- QT学习笔记----登录对话框
- QT学习笔记之对话框
- 可扩展的对话框
- 可扩展对话框
- 可扩展的对话框
- qt-扩展对话框
- 《Series40可扩展应用程序开发》学习笔记
- Qt学习14——可拓展对话框
- QT学习笔记4---登陆对话框
- Qt学习笔记01_标准对话框
- LeetCode 260. Single Number III
- Linux 设备驱动开发思想 —— 驱动分层与驱动分离
- Google Chrome源码剖析【序】
- java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
- icmp简介
- qt学习笔记可扩展对话框
- vb作业
- MySql5.7.11 for Windows 安装(二)
- DuiLib(9)——关于字体、html及默认属性
- 解析一个有关sizeof用法的题目--sizeof(i++)
- 应用程序无法正常启动(0xc000007b)
- CUDA编程(八)树状加法
- 二分 51Nod1686 第K大区间
- 害死人不偿命的(3n+1)猜想