QT学习 第一章:基本对话框--利用Qt Designer设计多个UI界面

效果截图:

创建上文件夹Designers,使用Designer设计三个UI界面:

First.ui

Second.ui

Third.ui

下面三个代码文件的源码:

/** Object: Designers ** Desc: Designers 在程序中使用多个UI界面 ** File: main.cpp ** Compile:qmake-qt4 -project;qmake-qt4;make; ** Author: LiXiujie www.xiujie.cn ** Date: 2011-05-20 ** Note: 编译说明: ** qmake-qt4 -prject 自动生成程序的项目文件(*.pro); ** 打开工程文件加入 FORMS += / Second.ui / First.ui / Third.ui ** qmake-qt4 用于生成程序的Makefile文件; ** make 编译 Makefile 文件得到可执行文件。 ** */ #include <QApplication> // 所有QT图形化应用程序必须包含此文件,它包含了QT图形化应用程序的各种资源、基本设置、控制流及事件处理等。 #include <QDialog> #include "MyWidget.h" // 自定义类 int main(int argc, char *argv[]){ QApplication app(argc, argv); MyWidget *dialog = new MyWidget; dialog->show(); return app.exec(); }

/** Object: Designers ** Desc: Designers 在程序中使用多个UI界面 ** File: MyWidget.h ** Class: MyWidget ** Compile:qmake-qt4 -project;qmake-qt4;make; ** Author: LiXiujie www.xiujie.cn ** Date: 2011-05-20 ** Note: 编译说明: ** qmake-qt4 -prject 自动生成程序的项目文件(*.pro); ** qmake-qt4 用于生成程序的Makefile文件; ** make 编译 Makefile 文件得到可执行文件。 ** */ #ifndef MYWIDGET_H #define MYWIDGET_H #include <QWidget> #include "ui_First.h" #include "ui_Second.h" #include "ui_Third.h" class MyWidget : public QWidget { Q_OBJECT public: explicit MyWidget(QWidget *parent = 0); signals: public slots: void slotChild(); private: Ui::First m_firstUI; Ui::Second m_secondUI; Ui::Third m_thirdUI; }; #endif // MYWIDGET_H

/** Object: Designers ** Desc: Designers 在程序中使用多个UI界面 ** File: MyWidget.cpp ** Class: MyWidget ** Compile:qmake-qt4 -project;qmake-qt4;make; ** Author: LiXiujie www.xiujie.cn ** Date: 2011-05-20 ** Note: 编译说明: ** qmake-qt4 -prject 自动生成程序的项目文件(*.pro); ** qmake-qt4 用于生成程序的Makefile文件; ** make 编译 Makefile 文件得到可执行文件。 ** */ #include "MyWidget.h" MyWidget::MyWidget(QWidget *parent) : QWidget(parent){ QTabWidget *pTabWidget = new QTabWidget(this); // TabWidget 控件, 选项卡控件 QWidget *pWidget_first = new QWidget; m_firstUI.setupUi((QDialog*)pWidget_first); QWidget *pWidget_second = new QWidget; m_secondUI.setupUi((QDialog*)pWidget_second); pTabWidget->addTab(pWidget_first, "First Tab"); // 添加一个选项卡 pTabWidget->addTab(pWidget_second, "Second Tab"); pTabWidget->resize(300, 300); // 设置控件宽长 /* 绑定UI界面中按钮点击事件处理函数 */ connect(m_firstUI.pushButton_Child, SIGNAL(clicked()), this, SLOT(slotChild())); connect(m_secondUI.pushButton_Close, SIGNAL(clicked()), this, SLOT(close())); } void MyWidget::slotChild(){ QDialog *pDialog_third = new QDialog; m_thirdUI.setupUi(pDialog_third); connect(m_thirdUI.pushButton_Close, SIGNAL(clicked()), pDialog_third, SLOT(close())); pDialog_third->exec(); // 显示对话框 }

下面三个UI文件源码:

First.ui

<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>First</class> <widget class="QDialog" name="First"> <property name="windowModality"> <enum>Qt::NonModal</enum> </property> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>300</width> <height>250</height> </rect> </property> <property name="windowTitle"> <string>Dialog</string> </property> <widget class="QLabel" name="label"> <property name="geometry"> <rect> <x>100</x> <y>100</y> <width>100</width> <height>20</height> </rect> </property> <property name="text"> <string>这是第一个 UI!!</string> </property> </widget> <widget class="QPushButton" name="pushButton_Child"> <property name="geometry"> <rect> <x>200</x> <y>200</y> <width>80</width> <height>25</height> </rect> </property> <property name="text"> <string>子窗口</string> </property> </widget> </widget> <resources/> <connections/> </ui>

Second.ui

<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>Second</class> <widget class="QDialog" name="Second"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>300</width> <height>250</height> </rect> </property> <property name="windowTitle"> <string>Second</string> </property> <widget class="QLabel" name="label"> <property name="geometry"> <rect> <x>100</x> <y>100</y> <width>100</width> <height>20</height> </rect> </property> <property name="text"> <string>这是第二个 UI!!</string> </property> </widget> <widget class="QPushButton" name="pushButton_Close"> <property name="geometry"> <rect> <x>200</x> <y>200</y> <width>80</width> <height>25</height> </rect> </property> <property name="text"> <string>关闭</string> </property> </widget> </widget> <resources/> <connections/> </ui>

Third.ui

<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>Third</class> <widget class="QDialog" name="Third"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>300</width> <height>250</height> </rect> </property> <property name="windowTitle"> <string>Third Dialog</string> </property> <widget class="QLabel" name="label"> <property name="geometry"> <rect> <x>100</x> <y>100</y> <width>100</width> <height>20</height> </rect> </property> <property name="text"> <string>这是第三个 UI!!</string> </property> </widget> <widget class="QPushButton" name="pushButton_Close"> <property name="geometry"> <rect> <x>200</x> <y>200</y> <width>80</width> <height>25</height> </rect> </property> <property name="text"> <string>关闭</string> </property> </widget> </widget> <resources/> <connections/> </ui>

QT学习 第一章:基本对话框--利用Qt Designer设计多个UI界面相关推荐

  1. QT学习开发笔记(项目实战之智能家居物联 UI 界面开发 )

    智能家居物联 UI 界面开发 项目路径为 4/01_smarthome/01_smarthome/01_smarthome.pro,先看项目界面.项目界面如 下,采用暗黑主题设计,结合黄色作为亮色,让 ...

  2. QT学习笔记(三):Qt软件打包发布(QT5.8 _msvc2013_64+Win10_64)

    QT学习笔记(三):Qt软件打包发布(QT5.8 _msvc2013_64+Win10_64) 1.编译方式介绍: 2.动态编译方式打包发布QT程序: 方法一:手动复制 方法二:使用工具 问题& ...

  3. QT学习笔记(二):QT MinGW 和 MSVC 编译方式

    QT学习笔记(二):QT MinGW 和 MSVC 编译方式 Qt 中有两种方式编译:一种是MinGW ,另一种MSVC,是使用两种不同的编译器. 1.MSVC是指微软的VC编译器: 2.MingGW ...

  4. 逻辑学学习:第一章:导论

    逻辑学学习:第一章:导论 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 开始学习逻辑学,教材为<<普通逻辑学>>,作者杨树森, ...

  5. QT开发学习-第一章-QT简介

    QT简介 一.QT简介 1.QT简介 2.QT优点 二.QT开发工具 1.Qt Creator 2.Qt Designer 3.Qt Linguist 4.Qt Assistant 5.Qmake 6 ...

  6. distiller的另一个实例正忙于启动_PYQT5学习(02):利用Qt Designer制作第一个窗口程序

    目标 利用Qt Designer设计窗口界面 使用PyUIC把Qt Designer生成的UI文件转换为py文件 使用转换生成的py文件 创建项目 启动启动pycharm并创建项目 这一环节在这里就不 ...

  7. Qt学习笔记-5-Qt标准对话框之QFileDialog

    所谓标准对话框,其实就是 Qt 内置的一些对话框,比如文件选择.颜色选择等等. QFileDialog 是 Qt 中用于文件打开和保存的对话框. 之前写的openAction只是弹出了一个消息对话框, ...

  8. 《浅谈Cache Memory》 学习-第一章

    序 近些年,我在阅读一些和处理器相关的论文与书籍,有很多些体会,留下了若干文字.其中还是有一片领域,我一直不愿意书写,这片领域是处理器系统中的Cache Memory.我最后决定能够写下一段文字,不仅 ...

  9. Intel汇编语言程序设计学习-第一章 基本概念

    第一章基本概念 1.1  简单介绍 本书着重讲述MS-Windows平台上IA-32(Intel Architecture 32bit,英特尔32位体系架构)兼容微处理器的汇编语言程序设计,可以使用I ...

最新文章

  1. Android SDK 路径修改
  2. github里的默认域_GitMAD 一款扫描Github上的敏感信息和数据泄漏工具
  3. (转)分布式文件存储FastDFS(五)FastDFS常用命令总结
  4. 阿里云容器服务新增支持Kubernetes编排系统,性能重大提升
  5. 推荐一个高质量的git命名查询和学习的github仓库git-recipes
  6. VC++ 在两个程序中 传递字符串等常量值的方法:使用了 WM_COPYDATA 消息的
  7. 这个世界最贵的奢侈品永远是事业
  8. 程序员怎样练出倒三角身材
  9. [运维笔记] PowerShell (模块).模块的查找、安装、卸载、更新、保存、发布
  10. 第3讲 zend原理剖析
  11. Bootstrap 时间控件 datetimepicker
  12. pr录制自己声音杂音很重
  13. python如何翻译成中文的代码-Python实现中文数字转换为阿拉伯数字的方法示例
  14. 【小学】综合素质脑图笔记
  15. 【论文阅读】(2022)A goal-driven ruin and recreate heuristic for the 2D variable-sized bin packing prob...
  16. 如何解决数组下标越界异常
  17. 有了方差为什么需要标准差?
  18. 计算机辅助曹瞒走华容(华容道)算法
  19. 线代[2]|对极易混淆概念的梳理—线性相关与线性无关、极大线性无关部分组与秩与基础解系、向量空间的基与维数
  20. python内置函数format的使用方法 python format函数怎么用

热门文章

  1. 网络安全技术课程小结(一)
  2. Java将图片转为Base64
  3. libapache2-mod-php5 apache,Debian Etch libapache2-mod-php5 with bundled libgd
  4. 女人要优雅,男人要幽默
  5. 图形化界面设计软件简要介绍
  6. 底物的分子描述符计算及 CYP450 酶-底物选择性技术研究
  7. java emoji表情 乱码_java 微信昵称带有emoji 表情乱码
  8. 是不是选择任何一个方向,都会游向同一个宿命呢
  9. 从UIL库谈Android图片加载中需要注意的事情
  10. JS图片img旋转、放大、缩小