一.第一阶段

运行结果(GIF动图):

day12.pro

QT       += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++11# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0SOURCES += \main.cpp \widget.cppHEADERS += \widget.h# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

widget.h

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>class Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();
};
#endif // WIDGET_H

widget.cpp

#include "widget.h"
#include<QPushButton>
#include<QDialog>
Widget::Widget(QWidget *parent): QWidget(parent)
{this->resize(640,480);QPushButton* pb=new QPushButton("Dailog",this);pb->show();QDialog* dialog= new QDialog;connect(pb,SIGNAL(clicked()),dialog,SLOT(exec()));
}Widget::~Widget()
{}

main.cpp

#include "widget.h"#include<QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();return a.exec();
}

二.第二阶段

运行结果(GIF动图):


day12.pro

QT       += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++11# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0SOURCES += \main.cpp \widget.cppHEADERS += \widget.h# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

widget.h

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>class Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();
private:void initDialog();
public slots:void showDialog();
private:QDialog* _dialog;
};
#endif // WIDGET_H

widget.cpp

#include "widget.h"
#include<QDialog>
#include<QDebug>
#include<QGridLayout>
#include<QHBoxLayout>
#include<QPushButton>
#include<QLabel>
#include<QLineEdit>
Widget::Widget(QWidget *parent): QWidget(parent)
{this->resize(640,480);QPushButton* pb=new QPushButton("Dailog",this);pb->show();_dialog= new QDialog;connect(pb,SIGNAL(clicked()),this,SLOT(showDialog()));initDialog();
}
void Widget::initDialog()
{QGridLayout* grid=new QGridLayout(_dialog);QHBoxLayout* hBox=new QHBoxLayout;QPushButton* ok=new QPushButton("确认");QPushButton* cancel= new QPushButton("取消");QLabel* userLabel=new QLabel("用户:");QLineEdit* userEdit=new QLineEdit;QLabel* passWdLabel = new QLabel("密码:");QLineEdit* passwdEdit = new QLineEdit;grid->addWidget(userLabel,0,0,1,1);grid->addWidget(userEdit,0,1,1,2);grid->addWidget(passWdLabel,1,0,1,2);grid->addWidget(passwdEdit,1,1,1,2);grid->addLayout(hBox,2,0,1,3);hBox->addSpacing(80);hBox->addWidget(ok);hBox->addWidget(cancel);passwdEdit->setEchoMode(QLineEdit::Password);connect(cancel,SIGNAL(clicked()),_dialog,SLOT(reject()));//取消按钮connect(ok,SIGNAL(clicked()),_dialog,SLOT(accept()));//确认按钮
}void Widget::showDialog()
{int ret=_dialog->exec();qDebug()<<ret<<endl;
}Widget::~Widget()
{}

main.cpp

#include "widget.h"#include<QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();return a.exec();
}

三.附:概念

2 触发一个模式对话框



QT每日一练day12:QDailog相关推荐

  1. QT每日一练day4:ubuntu中使用QT

    (本文主要是为了说明QT的跨平台特性)   一.安装QT sudo apt-get install qt5-default qtcreator cmake 二.打开QT 可以点击图标或命令行方式: 三 ...

  2. QT每日一练day1:第一个程序

    参考博文:Qt常见类.窗口类继承关系树图 QT每日一练(1):第一个程序 最终效果(GIF动图): step1: step2: step3: step4: step5: step6: step7: s ...

  3. QT每日一练day29:QT中的多线程探究

    一.未使用多线程,则w0先运行完后,w1才开始运行 运行结果(GIF动图): main.cpp xiaowen_QT_day29.pro QT+=widgets SOURCES += \main.cp ...

  4. QT每日一练day27:绘制不规则窗体

    注:本文本来应该是以一个不规则的图片作为历程的,,忘记了!!!!     一.第一阶段:隐藏窗体框架 运行结果(GIF动图): widget.cpp 二.第二阶段:将窗口设置为透明 运行结果(GIF动 ...

  5. QT每日一练day26:绘制图片

    一.第一阶段 发现上述图片没有显示全!!!!! 二.第二阶段 设置宽高比,平滑转换 运行结果(GIF动图): 发现上述图片在数次缩放后会产生失真!!!!! 三.第三阶段 为了避免图像缩放过程中产生失真 ...

  6. QT每日一练day25:触发绘画事件

    运行结果(GIF动图): widget.cpp 附代码: xiaowen_QT_day25.pro QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT ...

  7. QT每日一练day24:绘画事件

    一.第一阶段 设置线条粗细 二.第二阶段:设置笔的样式 如:虚线 三.第三阶段:绘制矩形 四.第四阶段:设置颜色 轮廓颜色 笔刷颜色 笔刷样式 五.第五阶段:绘制其他形状图像和文字 六.第六阶段:图像 ...

  8. QT每日一练day23:鼠标进入与离开事件

    运行结果(GIF动图): xiaowen_QT_day23.pro QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFI ...

  9. QT每日一练day22:键盘事件

    一.第一阶段--键盘按键按下事件 运行结果(GIF动图): xiaowen_QT_day22.pro QT += core guigreaterThan(QT_MAJOR_VERSION, 4): Q ...

最新文章

  1. CLASSPATH的作用
  2. Voat —— 基于 ASP.NET 的 Reddit 高仿系统
  3. [PM Tools]软件项目进度跟踪表v4.0
  4. 定义交货输出确定过程(Output Determination Procedure)
  5. ExtJS学习--------Ext.Element中的经常使用事件和其它重要的方法学习(实例)
  6. java中有关线程的题目
  7. docker学习记录 docker 脚本(一)
  8. 对‘pthread_create’未定义的引用_2018年度‘龙虎榜’统计分析(一)
  9. 开发S2B2C商城系统需要多少钱
  10. 图像的旋转——imrotate
  11. 苹果电脑打不开网页连接不到服务器,苹果电脑chrome打不开网页怎么办_MAC上的chrome打不开网页如何解决-win7之家...
  12. 在线sql进行Excel表格拆分
  13. android5.1修改默认锁屏方式(去除锁屏)
  14. 计算机硬件检测和数据恢复资料,探究职业学校计算机专业课程教学方案——以《计算机硬件检测维修与数据恢复》项目课程为例...
  15. N1 小钢炮docker安装迅雷方法
  16. QT关于界面常用设置
  17. wince系统报错异常总结
  18. 机器学习项目(一)——垃圾邮件的过滤技术
  19. 利用计算机对恒星做仿真,全国计算机等级考试模拟考试系统 上机模拟软件
  20. cursor.execute

热门文章

  1. 第一章python绝对温标身体质量指数bmi
  2. 基于JAVA+SpringMVC+Mybatis+MYSQL的旅游景点门票售票管理系统
  3. 基于JAVA+SSH+MYSQL的水果商城系统
  4. MATLAB1阶零模型,MATLAB 空间计量模型的实现
  5. [洛谷P3550][POI2013]TAK-Taxis
  6. 08-可滚动Widget
  7. react学习笔记2之正确使用状态
  8. 《编写可维护的Javascript》学习总结
  9. CSS3(七) 前端预处理技术(Less、Sass、CoffeeScript)
  10. 站立会议中发现的一些新问题