QDialog 使用Demo
【1】.pro
QT += core gui greaterThan(QT_MAJOR_VERSION, ): QT += widgets TARGET = TestDialog
TEMPLATE = app # The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as 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 you use 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. SOURCES += main.cpp\
dialog.cpp HEADERS += dialog.h FORMS += dialog.ui
【2】.h
#ifndef DIALOG_H
#define DIALOG_H #include <QDebug>
#include <QDialog>
#include <QPushButton>
#include <QHBoxLayout> namespace Ui
{
class Dialog;
} class MyDialog : public QDialog
{
public:
MyDialog(QWidget *parent = Q_NULLPTR);
~MyDialog(); private:
void init(); private:
QPushButton* m_p1;
QPushButton* m_p2; }; class Dialog : public QDialog
{
Q_OBJECT public:
explicit Dialog(QWidget *parent = );
~Dialog(); private slots:
void onPushButton(); private:
Ui::Dialog *ui;
MyDialog *m_pDialog;
}; #endif // DIALOG_H
【3】.cpp
#include "dialog.h"
#include "ui_dialog.h" MyDialog::MyDialog(QWidget *parent) : QDialog(parent)
{
init();
} MyDialog::~MyDialog()
{ } void MyDialog::init()
{
m_p1 = new QPushButton(this);
m_p1->setText(QString("OK"));
m_p2 = new QPushButton(this);
m_p2->setText(QString("Cancel"));
connect(m_p1, &QPushButton::clicked, this, &MyDialog::accept);
connect(m_p2, &QPushButton::clicked, this, &MyDialog::reject);
QHBoxLayout* pHLayout = new QHBoxLayout(this);
pHLayout->addWidget(m_p1);
pHLayout->addWidget(m_p2);
setLayout(pHLayout);
} Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
m_pDialog = new MyDialog();
connect(ui->pushButton, &QPushButton::clicked, this, &Dialog::onPushButton);
} Dialog::~Dialog()
{
delete ui;
if (m_pDialog != Q_NULLPTR)
{
delete m_pDialog;
m_pDialog = Q_NULLPTR;
}
} void Dialog::onPushButton()
{
int nRet = m_pDialog->exec();
if (nRet == QDialog::Accepted)
{
qDebug() << "Click OK Button";
qApp->exit();
}
else if (nRet == QDialog::Rejected)
{
qDebug() << "Click Cancel Button";
return;
}
}
【4】main
#include "dialog.h"
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.show(); return a.exec();
}
【5】验证一个问题
Good Good Study, Day Day Up.
顺序 选择 循环 总结
QDialog 使用Demo的更多相关文章
- QT 随笔目录
[1]基础部分 <信号和槽机制> <信号与槽知识点> <QString 与 string转换> <QT 继承QWidget && 继承QDia ...
- qt5之设置无边窗口移动
Note qt version: 5.12 qt creator: 4.13 本文将介绍 设置无边窗口和设置窗口的移动 你要知道: QDialog 和 QMainWindow都是 QWidget的派生 ...
- QT 入门 -QApplication QPushButton QDialog Ui类型的手工使用
QT 1.工具 assistant 帮助文档 qtconfig QT配置工具 qmake QT的make与项目文件智能创建工具 uic UI界面的设计文件的编译工具 mo ...
- Qt Creator简单计算器的Demo
小编在期末数据结构课设中遇到要做可视化界面的问题,特意去学习了一下Qt的用法,今天就来给大家分享一下. 我用的是Qt5.80,当然这只是一个简易的计算器Demo,,请大家勿喷. 首先我创建了一个Qt ...
- QDialog对话框
QDialog对话框,用来实现那些只是暂时存在的用户界面,是独立的窗口,但通常也有父窗口对话框有模态和非模态两种,,非模态对话框的行为和使用方法都类似于普通的窗口,模态对话框则有所不同,当模态对话框显 ...
- 通过一个demo了解Redux
TodoList小demo 效果展示 项目地址 (单向)数据流 数据流是我们的行为与响应的抽象:使用数据流能帮我们明确了行为对应的响应,这和react的状态可预测的思想是不谋而合的. 常见的数据流框架 ...
- 很多人很想知道怎么扫一扫二维码就能打开网站,就能添加联系人,就能链接wifi,今天说下这些格式,明天做个demo
有些功能部分手机不能使用,网站,通讯录,wifi基本上每个手机都可以使用. 在看之前你可以扫一扫下面几个二维码先看看效果: 1.二维码生成 网址 (URL) 包含网址的 二维码生成 是大家平时最常接触 ...
- 在线浏览PDF之PDF.JS (附demo)
平台之大势何人能挡? 带着你的Net飞奔吧!:http://www.cnblogs.com/dunitian/p/4822808.html#skill 下载地址:http://mozilla.gith ...
- 【微框架】Maven +SpringBoot 集成 阿里大鱼 短信接口详解与Demo
Maven+springboot+阿里大于短信验证服务 纠结点:Maven库没有sdk,需要解决 Maven打包找不到相关类,需要解决 ps:最近好久没有写点东西了,项目太紧,今天来一篇 一.本文简介 ...
随机推荐
- 连连看java版
主界面 import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt. ...
- 【SQL】如何使用SQL like 方法和SQL [charlist] 通配符(SQL like的拓展)
1.like 相关用法 '%a' //以a结尾的数据 'a%' //以a开头的数据 '%a%' //含有a的数据 ‘_a_’ //三位且中间字母是a的 '_a' //两位 ...
- React Native入坑记录
1.render中如果使用props,直接用this.props.xxx,如果是在JSX中,用{this.props.xxx} 2.警告each child in an array or iterat ...
- mysql 数据表操作 目录
mysql 数据表操作 存储引擎介绍 mysql 使用存储引擎 mysql 数据表的增删改查 mysql 数据类型 mysql 约束条件
- MongoDB update修改器: 针对Fields的$修改器 $inc $set $unset
MongoDB update修改器: $inc $set $unset $push $pull $pop 针对Fields的$修改器 $set: { $set: { key: value } } $s ...
- 如何修改帝国cms文章点击量默认值和成倍增加
我们在帝国cms发布完文章,在不点击的情况下,“点击量”默认显示为0,请问有什么方法,修改关注默认值吗?这个可以在增加信息时,“特殊属性”标签里修改点击量,如下图 有朋友问有没其他好的方法快速增加.成 ...
- python创建有序字典及字典按照值的大小进行排序
有序字典 在Python中,字典类型里面的元素默认是无序的,但是我们也可以通过collections模块创建有序字典 # -*- coding:utf-8 -*- # python有序字典需导入模块c ...
- dxRatingControl使用
Properties AllowHover:是否鼠标滑动选择 CheckedGlyph:选中后显示的图像 Glyph:显示的图像 HoverGlyph:鼠标滑动时显示的图像 ItemCount:项目总 ...
- 常见Chrome 插件
Chrome插件网:http://chromecj.com/downloadstart.html Chrome浏览器:http://chromecj.com/chrome/2014-09/177.ht ...
- Linux Shell的18条常用命令整理
1. ls: 类似于dos下的dir命令 ls最常用的参数有三个:-a -l -F. ls –a Linux上的文件以.开头的文件被系统视为隐藏文件,仅用ls命令是看不到他们的,而用ls -a除了 ...