2.关于QT中的Dialog(模态窗口),文件选择器,颜色选择器,字体选择器,消息提示窗口
1
新建一个空项目
A
编写 .pro文件
|
QT HEADERS MyDialog.h SOURCES MyDialog.cpp |
B
编写MyDialog.h
|
#ifndef #define #include class { Q_OBJECT public: explicit QString void signals: public void }; #endif |
C
编写:MyDialog.cpp
#include "MyDialog.h" #include <QPushButton> #include <QDebug> #include <QFileDialog> #include <QFileInfo> #include <QColorDialog> #include <QFontDialog> #include <QMessageBox> #include <QPainter> #include <QApplication> MyDialog::MyDialog(QWidget *parent) : QDialog(parent) {
QPushButton* button = new QPushButton("Click me",this);
connect(button, SIGNAL(clicked()), this, SLOT(slotButtonClick())); } void MyDialog::slotButtonClick() {
#if 0 QDialog* dlg = new QDialog; int ret; QPushButton* button = new QPushButton(dlg); connect(button, SIGNAL(clicked()), dlg, SLOT(reject())); /* * 在模态对话框中,exec有自己的消息循环,并且把app的消息循环接管了 * 如果Dialog是通过exec来显示,那么可以通过accepted或者rejected来关闭 * 窗口,如果Dialog是通过show来显示,那么可以通过close来关闭窗口, * 这个和QWidget一样的 * * 有许多特殊的dailog:文件选择,MessageBox,颜色选择,字体选择,打印预览,打印 */ ret = dlg->exec(); if(ret == QDialog::Accepted) {
qDebug() << "accepted"; } if(ret == QDialog::Rejected) {
qDebug() << "rejected"; } //上面的运行结果如下: #endif #if 0 //通过下面的方式打开保存文件 QString strFilename = QFileDialog::getSaveFileName( NULL, "Select file for save", _strDir, "pic file (*.png *.jpg)"); //运行结果: #endif #if 0 //打开一个文件 #endif #if 0 //选择一个存在的文件夹 QString strFilename = QFileDialog::getExistingDirectory(); if(strFilename.isEmpty()) {
qDebug() << "select none"; return; } qDebug() << strFilename; QFileInfo fileInfo(strFilename); _strDir = fileInfo.filePath(); #endif #if 0 //颜色选择框 QColorDialog color; color.exec(); QColor c = color.selectedColor(); #endif #if 0 //字体选择器 QFontDialog fontDialog; fontDialog.exec(); QFont font = fontDialog.selectedFont(); #endif #if 0 //MessageBox,消息提示窗口 int ret = QMessageBox::question(this, "????", "realy do .......", QMessageBox::Yes| QMessageBox::No| QMessageBox::YesAll| QMessageBox::NoAll); if(ret == QMessageBox::Yes) {
qDebug() << "user select yes"; } if(ret == QMessageBox::No) {
qDebug() << "user select no"; } #endif } void MyDialog::paintEvent(QPaintEvent *) {
QPainter p(this); p.drawLine(QLine(0,0,200,200)); } int main(int argc,char* argv[]) {
QApplication app(argc,argv); MyDialog dlg; dlg.show(); return app.exec(); } |
2.关于QT中的Dialog(模态窗口),文件选择器,颜色选择器,字体选择器,消息提示窗口的更多相关文章
- Swift-打开其它Storyboard中的自定义模态窗口
本文的方法针对OS X应用开发. 如果想在某个ViewController中,用模态窗口的方式,打开某个Storyboard中定义的WindowController.可用以下方式. let story ...
- Qt中使用DOM解析XML文件或者字符串二(实例)
介绍 在Qt中提供了QtXml模块实现了对XML数据的处理,我们在Qt帮助中输入关键字QtXml Module,可以看到该模块的类表.在这里我们可以看到所有相关的类,它们主要是服务于两种操作XML文档 ...
- Qt中的非模式窗口配置;
Test7_5A::Test7_5A(QWidget *parent) : QMainWindow(parent){ ui.setupUi(this); m_searchwin = new Searc ...
- Qt中使用DOM解析XML文件或者字符串(实例)
因为需要读取配置文件,我的配置文件采用xml:因此编写了使用qt读取xml文件内容的代码,xml文件如下: <?xml version="1.0" encoding=&quo ...
- 19.QT对话框(文件对话框,颜色对话框,字体框,自定义对话框)
文件对话框 #include<QFileDialog> //文件对话框 void Dialog::on_pushButton_clicked() { //定义显示文件的类型 窗口标题 可供 ...
- Qt5:Qt中屏幕或窗口截图功能的实现
要想在Qt中实现屏幕或窗口截图功能 ,通常有两种方法: 1 -- 使用 QPixmap 类 2 -- 使用 QScreen类 然而虽然俩两种方法用到的类不相同,但是调用到的类成员函数的函数名称和参 ...
- [Win32]创建模态窗口
http://www.cnblogs.com/zplutor/archive/2011/02/20/1958973.html 在Win32编程中,如果要显示一个模态窗口,一般是先创建对话框模板,然后使 ...
- qt中建立图片资源文件
qt中如果你要添加图片资源文件我们需要执行以下步骤: (1)先找好一张图片,这里就不多说了,网上资源很多. (2)把我们找好的文件统一放到一个文件夹,然后拉到工程文件所在的文件夹下 (3)在qt中新建 ...
- iOS:视图切换的第一种方式:模态窗口
一.UIModalController:模态窗口(一个控制器模态出另一个控制器的模态窗口) 当我们在view controller A中模态显示view controller B的时候,A就充当pre ...
随机推荐
- [Vijos 2024]无向图最短路径
Description 无向图最短路径问题,是图论中最经典也是最基础的问题之一.本题我们考虑一个有 $n$ 个结点的无向图 $G$.$G$ 是简单完全图,也就是说 $G$ 中没有自环,也没有重边,但任 ...
- codeforces 651C Watchmen
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...
- hdu 5869 区间不同GCD个数(树状数组)
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- ●BZOJ 1233 [Usaco2009Open] 干草堆 tower
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1233 留坑.以后再来看看. (绝望,无奈,丧心...) (这个题的证明真的很诡异啊,看得我稀 ...
- hdu4729 树链剖分+二分
An Easy Problem for Elfness Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65535/65535 K (J ...
- bzoj 2734: [HNOI2012]集合选数
题目描述 <集合论与图论>这门课程有一道作业题,要求同学们求出{1, 2, 3, 4, 5}的所有满足以 下条件的子集:若 x 在该子集中,则 2x 和 3x 不能在该子集中. 同学们不喜 ...
- Docker学习笔记【一】
[本篇学习笔记来源于 Docker 从入门到实践] 1.什么事Docker?[What] Docker在容器的基础上,进行了进一步的封装,从文件系统.网络互联到进程隔离等,极大的简化了容器的创建和维护 ...
- HTTP 协议详解(超级经典)-转
什么是HTTP协议 协议是指计算机通信网络中两台计算机之间进行通信所必须共同遵守的规定或规则,超文本传输协议(HTTP)是一种通信协议,它允许将超文本标记语言(HTML)文档从Web服务器传送到客户端 ...
- iframe嵌套页面 音频在微信公众号环境无法播放
在微信公众号中 没有iframe的时候window.WeixinJSBridge为对象,有iframe时为undefined 要使用 window.parent.WeixinJSBridge得到 if ...
- 89. Gray Code(中等,了解啥是 gray code)
知道啥是 gray code 就是收获了. 下面介绍了 gray code 发明的 motivation, 了解动机后就知道啥是 gray code 了. https://zh.wikipedia.o ...