博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Qt之对话框设计——可扩展对话框
阅读量:6277 次
发布时间:2019-06-22

本文共 2738 字,大约阅读时间需要 9 分钟。

彩虹利用setSizeConstraint(QLayout::SetFixedSize)方法使对话框尺寸保持相对固定(有控件决定),不能经过拖动改变大小。


extension.h

#ifndef EXTENSION_H#define EXTENSION_H#include 
#include
class Extension : public QDialog{ Q_OBJECTpublic: Extension(QWidget *parent = 0, Qt::WFlags flags = 0); ~Extension(); void createBaseInfo(); void createDetaiInfo();private: QWidget *baseWidget; QWidget *detaiWidget; public slots: void sl_Extension(); };#endif // EXTENSION_H

extension.cpp

#include "extension.h"#include 
#include
#include
#include
#include
#include
Extension::Extension(QWidget *parent, Qt::WFlags flags) : QDialog(parent, flags){ setWindowTitle(tr("Extension Dialog")); createBaseInfo(); createDetaiInfo(); QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addWidget(baseWidget); mainLayout->addWidget(detaiWidget); mainLayout->setSpacing(10); mainLayout->setSizeConstraint(QLayout::SetFixedSize);}Extension::~Extension(){}void Extension::createBaseInfo(){ baseWidget = new QWidget; QLabel *labName = new QLabel(tr("Name:")); QLabel *labSex = new QLabel(tr("Sex:")); QLineEdit *edtName = new QLineEdit; QComboBox *cbbSex = new QComboBox; cbbSex->insertItem(0,tr("male")); cbbSex->insertItem(1,tr("female")); QPushButton *btnOk = new QPushButton(tr("Ok")); QPushButton *btnDetai = new QPushButton(tr("Detai")); connect(btnDetai,SIGNAL(clicked()),this,SLOT(sl_Extension())); QGridLayout *baseLayout = new QGridLayout(baseWidget); baseLayout->addWidget(labName,0,0); baseLayout->addWidget(edtName,0,1); baseLayout->addWidget(btnOk,0,2); baseLayout->addWidget(labSex,1,0); baseLayout->addWidget(cbbSex,1,1); baseLayout->addWidget(btnDetai,1,2); baseLayout->setMargin(10); baseLayout->setSpacing(10);}void Extension::createDetaiInfo(){ detaiWidget = new QWidget; QLabel *labAge = new QLabel(tr("Age:")); QLabel *labDepartment = new QLabel(tr("Department:")); QLabel *labEmail = new QLabel(tr("Email:")); QLineEdit *edtAge = new QLineEdit; QComboBox *cbbDepartment = new QComboBox; cbbDepartment->insertItem(0,tr("Department 1")); cbbDepartment->insertItem(1,tr("Department 2")); cbbDepartment->insertItem(2,tr("Department 3")); QLineEdit *edtEmail = new QLineEdit; QGridLayout *detaiLayout = new QGridLayout(detaiWidget); detaiLayout->addWidget(labAge,0,0); detaiLayout->addWidget(labDepartment,1,0); detaiLayout->addWidget(labEmail,2,0); detaiLayout->addWidget(edtAge,0,1); detaiLayout->addWidget(cbbDepartment,1,1); detaiLayout->addWidget(edtEmail,2,1); detaiLayout->setMargin(10); detaiLayout->setSpacing(10); detaiWidget->hide();}void Extension::sl_Extension(){ if (detaiWidget->isHidden()) { detaiWidget->show(); } else { detaiWidget->hide(); }}

转载地址:http://pkfva.baihongyu.com/

你可能感兴趣的文章
pitfall override private method
查看>>
!important 和 * ----hack
查看>>
聊天界面图文混排
查看>>
控件的拖动
查看>>
svn eclipse unable to load default svn client的解决办法
查看>>
Android.mk 文件语法详解
查看>>
QT liunx 工具下载
查看>>
内核源码树
查看>>
Java 5 特性 Instrumentation 实践
查看>>
AppScan使用
查看>>
Java NIO框架Netty教程(三) 字符串消息收发(转)
查看>>
Ucenter 会员同步登录通讯原理
查看>>
php--------获取当前时间、时间戳
查看>>
Spring MVC中文文档翻译发布
查看>>
docker centos环境部署tomcat
查看>>
JavaScript 基础(九): 条件 语句
查看>>
Linux系统固定IP配置
查看>>
配置Quartz
查看>>
Linux 线程实现机制分析
查看>>
继承自ActionBarActivity的activity的activity theme问题
查看>>