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 ...
随机推荐
- bzoj 1558: [JSOI2009]等差数列
Description Solution 把原数组变为差分数组,然后剩下的就十分显然了 区间查询用线段树维护 修改操作就是区间加法和两个单点修改 一个等差数列实际上就是 开头一个数字+数值相等的一段 ...
- 计蒜客NOIP2017提高组模拟赛(五)day1-机智的 AmyZhi
传送门 很水的题目啦QAQ #include<cstdio> #include<cstdlib> #include<algorithm> #include<c ...
- Linux命令-关机命令详解
关机命令:1.halt 立刻关机 2.poweroff 立刻关机 3.shutdown -h now 立刻关机(root用户使用) 4.shutdown -h 10 10分钟后自动关机 如果是通过sh ...
- Django Class Views
一.Base views View class django.views.generic.base.View 主要的基于类的基本视图.所有其他基于类的视图都从这个基类继承而来.它不是一个通用的视图,因 ...
- 移动端手势双击(MouseDown也可以在移动端响应,但是帧率太低)
void Update() { if (Input.touchCount > 0)//手指数量 { if(Input.GetTouch(0).phase == TouchPhase.Began ...
- VC++ 6.0中添加库文件和头文件
附加头文件包含 VC6.0中: VC6.0默认include包含路径:Tools>Options>Directories>Include files. 对于特定项目的头文件包含,在& ...
- 浏览器控制台调试json数据
var str ='{"code":0,"message":"","systemTime":"2017-10- ...
- $.messager.confirm 用法
<script type="text/javascript"> $(function () { $.messager.defaults = { ...
- 图片人脸检测——Dlib版(四)
上几篇给大家讲了OpenCV的图片人脸检测,而本文给大家带来的是比OpenCV更加精准的图片人脸检测Dlib库. 点击查看往期: <图片人脸检测——OpenCV版(二)> <视频人脸 ...
- Spring Boot Cache Redis缓存
1.集成MyBatis 1.1.引入maven依赖 1.2.生成Mapper 具体可以看MyBatis Generator官网 http://www.mybatis.org/generator/run ...