1、linux下安装Qt4请参考如下博文:

Qt4在linux下的安装

2、Qt4工程的创建请参考如下博文:

Qt4创建工程的几种方法:linux系统

3、可扩展对话框

通过纯代码的形式,建立工程。点击【Detail】按钮,显示扩展对话框

包括四部分:

工程文件:ExtensionDlg.pro

主程序文件:main.cpp

对话框类:ExtensionDlg.h

实现文件:ExtensionDlg.cpp

4、实例运行效果:

5、代码区:

main()函数

#include <QApplication>
#include "ExtensionDlg.h" int main(int argc, char* argv[])
{
QApplication app(argc, argv);
ExtensionDlg exDlg;
exDlg.show();
return app.exec();
}

ExtensionDlg.h文件

#ifndef EXTENSIONDLG_H
#define EXTENSIONDLG_H
#include <QtGui> class ExtensionDlg:public QDialog
{
Q_OBJECT //加入Q——OBJECT宏,程序中用到信号/槽等Qt核心机制的,都需要加入此宏
public:
ExtensionDlg(); //构造函数
void initBasicInfo(); //初始化基础信息
void initDetailInfo(); //初始化扩展信息
public slots: //声明共有槽
void slot2Extension(); //单击Detail按钮是被触发
private:
QWidget* baseWidget; //伸缩前对话框窗体,必须为指针
QWidget* detailWidget; //扩展后对话框窗体,必须为指针
}; #endif // EXTENSIONDLG_H

ExtensionDlg.cpp文件

#include "ExtensionDlg.h"

ExtensionDlg::ExtensionDlg()
{
setWindowTitle(tr("Extension Dialog")); //显示标题
initBasicInfo(); //初始化基本信息窗体
initDetailInfo(); //初始化扩展信息窗体 QVBoxLayout* layout = new QVBoxLayout; //定义一个垂直布局类实体,QHBoxLayout为水平布局类实体
layout->addWidget(baseWidget); //加入baseWidget
layout->addWidget(detailWidget); //加入DetailWidget
layout->setSizeConstraint(QLayout::SetFixedSize); //设置窗体缩放模式,此处设置为固定大小
layout->setSpacing(6); //窗口部件之间间隔大小
setLayout(layout); //加载到窗体上
} void ExtensionDlg::initBasicInfo()
{
baseWidget = new QWidget; //实例化baseWidget
QLabel* nameLabel = new QLabel(tr("Name")); //定义窗体部件
QLineEdit* nameEdit = new QLineEdit;
QLabel* sexLabel = new QLabel(tr("Sex"));
QComboBox* sexComboBox = new QComboBox; sexComboBox->addItem(tr("male"));
sexComboBox->addItem(tr("female")); QPushButton* okButton = new QPushButton(tr("OK"));
QPushButton* detailButton = new QPushButton(tr("Detail")); connect(detailButton, SIGNAL(clicked()), this, SLOT(slot2Extension())); //使用信号/槽机制 QDialogButtonBox* btnBox = new QDialogButtonBox(Qt::Horizontal); //QDialogButtonBox使用方法
btnBox->addButton(okButton, QDialogButtonBox::ActionRole);
btnBox->addButton(detailButton, QDialogButtonBox::ActionRole); QFormLayout* formLayout = new QFormLayout; //表单布局方法
formLayout->addRow(nameLabel, nameEdit);
formLayout->addRow(sexLabel, sexComboBox); QVBoxLayout* vboxLayout = new QVBoxLayout; //窗体顶级布局,布局本身也是一种窗口部件
vboxLayout->addLayout(formLayout); //顶层窗体加入表单
vboxLayout->addWidget(btnBox); //顶层窗体加入按钮
baseWidget->setLayout(vboxLayout); //加载到窗体上
} void ExtensionDlg::initDetailInfo()
{
detailWidget = new QWidget;
QLabel* ageLabel = new QLabel(tr("Age"));
QLineEdit* ageEdit = new QLineEdit;
ageEdit->setText(tr("25"));
QLabel* deptLabel = new QLabel(tr("Department"));
QComboBox* deptComboBox = new QComboBox; deptComboBox->addItem(tr("department 1"));
deptComboBox->addItem(tr("department 2"));
deptComboBox->addItem(tr("department 3"));
deptComboBox->addItem(tr("department 4")); QLabel* addressLabel = new QLabel(tr("Address"));
QLineEdit* addressEdit = new QLineEdit;
QFormLayout* formLayout = new QFormLayout;
formLayout->addRow(ageLabel, ageEdit);
formLayout->addRow(deptLabel, deptComboBox);
formLayout->addRow(addressLabel, addressEdit); detailWidget->setLayout(formLayout);
detailWidget->hide(); //将扩展信息窗口隐藏,hide()是Qt默认槽函数之一
} void ExtensionDlg::slot2Extension()
{
if(detailWidget->isHidden()) //ishidden()函数判断扩展窗口显隐状态
detailWidget->show();
else
detailWidget->hide();
}

ExtensionDlg.pro文件

TEMPLATE = app
TARGET =
DEPENDPATH +=
INCLUDEPATH +=
# Input
HEADERS += \
ExtensionDlg.h SOURCES += \
ExtensionDlg.cpp \
main.cpp

Qt4----子例化QDialog(可扩展对话框的使用)的更多相关文章

  1. Qt4--加密日记本(子例化QMainWindow文本加密解密)

    近来刚学习Qt4编程,想找个实例练习练习,于是产生了一个想法,就是怎么样做一个文本加密,这样,自己保存的一些文档可以通过软件 生成加密文本,到时候要看的时候,通过自己的软件读取就可以.既然有想法了,那 ...

  2. QT中实现应用程序的单例化

    一介绍 通过编写一个QSingleApplication类,来实现Qt程序的单例化,原文的作者是在Windows Vista + Qt4.4 下实现的,不过应用在其他平台上是没问题的.(本文是我在ht ...

  3. 利用python自动生成verilog模块例化模板

    一.前言 初入职场,一直忙着熟悉工作,就没什么时间更新博客.今天受“利奇马”的影响,只好宅在家中,写写技术文章.芯片设计规模日益庞大,编写脚本成了芯片开发人员必要的软技能.模块端口动不动就几十上百个, ...

  4. 62.在cdc文件上某些例化模块看不到的原因

    比如在顶层文件中,例化了几个模块,综合后打开cdc文件,会在structure/net中少几个例化模块,即看不到,但在顶层文件中还是存在的,只是ISE软件综合的问题而已,原因是在顶层或子模块中,有些应 ...

  5. Quartus中例化工程

    一般的例化工程,需要将要例化的对象的硬件语言放入到当前工程中,比如A要例化B,需要将B的编程文件加入当前工程进来. 还有一种方法不用这么麻烦,A工程用要例化B时,在library添加B的工程路径,就可 ...

  6. testbench中$display查看例化model里面信号方法以及$realtime用法

    前言 此为测试语法,不可综合: 流程: 1.在tb中可以这么写,检测clk_t_en的高电平,输出仿真时间位置,想查看的cnt_t是底层模块中的.这么会使得时间延迟一个周期: always @(pos ...

  7. Vscode生成verilog例化

    前言 手动例化又慢又容易出错,孩子老犯错怎么办? 当然是脚本一劳永逸. 流程 (1)在vscode中安装如下插件. (2)在电脑中安装python3以上的环境. 下载地址:https://www.py ...

  8. FPGA例化ROM存储表格

    FPGA例化ROM存储表格 1.选择ROM 2.填写数据位宽和深度 3.加载ROM初始化信息,coe文件

  9. Kotlin入门(28)Application单例化

    Application是Android的又一大组件,在App运行过程中,有且仅有一个Application对象贯穿应用的整个生命周期,所以适合在Application中保存应用运行时的全局变量.而开展 ...

随机推荐

  1. 从PyOpenCV到CV2

    安装cv2 http://hyry.dip.jp/files/opencv.zip 采用cv2重写的<Python科学计算>中的实例程序 读者可以在下面的页面中搜索“opencv”,并根据 ...

  2. ligh@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.3

    ligh@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.3

  3. SqlServer和Oracle中一些常用的sql语句10 特殊应用

    --482, ORACLE / SQL SERVER --订购数量超过平均值的书籍 WITH Orders_Book AS ( SELECT Book_Name, SUM(Qty) Book_Qty ...

  4. 解决 Xcode7 中多个模拟器的办法

    转自: http://www.oschina.net/code/snippet_196012_50574 1.关闭xcode 2.终端输入 sudo killall -9 com.apple.Core ...

  5. Linux DM9000网卡驱动程序完全分析

    Linux DM9000网卡驱动程序完全分析http://blog.csdn.net/ypoflyer/article/details/6209922

  6. 自己新建Xib 和.h .m文件关联

    代理中注意点 1.新建MainViewController.h 和 MainViewController.m文件: 新建Main.xib文件: 2.拖View到Main.xib中: 3.点击File’ ...

  7. C# 继承细节

    假定没有为类定义任何显式的构造函数,这样编译器就会为所有的类提供默认的构造函数,在后台会进行许多操作,编译器可以很好地解决层次结构中的所有问题,每个类中的每个字段都会初始化为默认值.但在添加了一个我们 ...

  8. ZOJ 3490 String Successor 字符串处理

    一道模拟题,来模拟进位 暴力的从右往左扫描,按规则求后继就好了.除了Sample已给出的,还有一些需要注意的地方: 9的后继是10,而不是00: (z)的后继是(aa),而不是a(a): 输入虽然最长 ...

  9. USACO Arithmetic Progressions 【构造等差数列】

    USER: Jeremy Wu [wushuai2] TASK: ariprog LANG: C++ Compiling... Compile: OK Executing... Test 1: TES ...

  10. POJ1273 最大流 EK算法

    套了个EK的模板 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdi ...