2.关于QT中的Dialog(模态窗口),文件选择器,颜色选择器,字体选择器,消息提示窗口
2014-12-13 22:47
423 查看
1
新建一个空项目
A
编写.pro文件
B
编写MyDialog.h
C
编写:MyDialog.cpp
1
新建一个空项目
A
编写.pro文件
QT += guiwidgets HEADERS += \ MyDialog.h SOURCES += \ MyDialog.cpp |
编写MyDialog.h
#ifndef MYDIALOG_H #define MYDIALOG_H #include <QDialog> class MyDialog:public QDialog { Q_OBJECT public: explicit MyDialog(QWidget *parent =0); QString _strDir; void paintEvent(QPaintEvent *); signals: public slots: void slotButtonClick(); }; #endif // MYDIALOG_H |
编写: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=newQPushButton("Clickme",this); connect(button,SIGNAL(clicked()),this,SLOT(slotButtonClick())); } voidMyDialog::slotButtonClick() { #if0 QDialog*dlg=newQDialog; intret; QPushButton*button=newQPushButton(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 #if0 //通过下面的方式打开保存文件 QStringstrFilename=QFileDialog::getSaveFileName( NULL, "Selectfileforsave", _strDir, "picfile(*.png*.jpg)"); //运行结果: #endif #if0 //打开一个文件 #endif #if0 //选择一个存在的文件夹 QStringstrFilename=QFileDialog::getExistingDirectory(); if(strFilename.isEmpty()) { qDebug()<<"selectnone"; return; } qDebug()<<strFilename; QFileInfofileInfo(strFilename); _strDir=fileInfo.filePath(); #endif #if0 //颜色选择框 QColorDialogcolor; color.exec(); QColorc=color.selectedColor(); #endif #if0 //字体选择器 QFontDialogfontDialog; fontDialog.exec(); QFontfont=fontDialog.selectedFont(); #endif #if0 //MessageBox,消息提示窗口 intret=QMessageBox::question(this,"????","realydo.......", QMessageBox::Yes|QMessageBox::No| QMessageBox::YesAll|QMessageBox::NoAll); if(ret==QMessageBox::Yes) { qDebug()<<"userselectyes"; } if(ret==QMessageBox::No) { qDebug()<<"userselectno"; } #endif } voidMyDialog::paintEvent(QPaintEvent*) { QPainterp(this); p.drawLine(QLine(0,0,200,200)); } intmain(intargc,char*argv[]) { QApplicationapp(argc,argv); MyDialogdlg; dlg.show(); returnapp.exec(); } |
相关文章推荐
- 2.关于QT中的Dialog(模态窗口),文件选择器,颜色选择器,字体选择器,消息提示窗口
- IE9下uploadify在模态窗口里无法弹出选择文件窗口的问题
- QT学习 之 对话框 (四) 字体对话框、消息对话框、文件对话框、进程对话框
- [QT]QFileDialog关于选择文件对话框中的几个信号的说明
- Qt - QDialog,QWidget实现模态及非模态(模态Widget不能有父窗口,如果设置无边框就不能阻塞父窗口,但是可以强行设置指定Qt::Dialog,还可以setAttribute(Qt::WA_ShowModal),很多讲究)good
- JBox - 模态窗口,工具提示和消息 jQuery 插件
- qt中获取打开文件路径,颜色对话框,字体对话框,自定义对话框,消息对话框,输入对话框
- QT-文件选择对话框的模态与非模态
- 关于模态窗口,showModelDialog的一些问题
- 安卓选择器类库,包括日期选择器、时间选择器、单项选择器、数字选择器、二三级联动选择器、省市区地址选择器、颜色选择器、文件目录选择器等,可自定义顶部及底部界面,可自定义窗口动画
- Unity3d调用system.windows.forms.dll使用OpenFileDialog打开文件选择窗口
- 安卓选择器类库,包括日期时间选择器、单项选择器、二三级联动选择器、地址选择器、颜色选择器、文件目录选择器、数字选择器等,可自定义顶部及底部界面,可自定义窗口动画。
- QT学习 之 对话框 (四) 字体对话框、消息对话框、文件对话框、进程对话框(超详细中文注释)
- JBox - 模态窗口,工具提示和消息 jQuery 插件
- 关于模态窗口window.showModalDialog .
- java swing中JFileChooser保存文件时,在文件选择窗口提示是否覆盖
- QT 打开文件选择窗口
- openFileDialog 选择文件
- 关于linux下的嵌入式文件系统以及flash文件系统选择(转)
- 利用C#实现标注式消息提示窗口