QMessageBox 在MAC下更加自然
说明
在MAC写过QT程序的程序员应该都知道,QT默认的QMessageBox没有MAC系统的效果,在网上找到了一篇关于这方面的文章,但是这篇文章写的有个缺点,就是使用信号的方式,使用起来很不方便。
解决
我自己写了一个类文件,以达到更好的使用QMessageBox。将下面的代码复制到你的工程中,就可以方便的使用。
头文件#ifndef QMESSAGEBOXEX_H
#define QMESSAGEBOXEX_H #include <QMessageBox> class QMessageBoxEx : public QMessageBox
{
public:
static QMessageBoxEx *shareQMessageBoxEx(); public:
QMessageBoxEx();
int information(QWidget *parent, const QString &title,
const QString &text, StandardButtons buttons = Ok,
StandardButton defaultButton = NoButton); int question(QWidget *parent, const QString &title,
const QString &text, StandardButtons buttons = StandardButtons(Yes | No),
StandardButton defaultButton = NoButton); int warning(QWidget *parent, const QString &title,
const QString &text, StandardButtons buttons = Ok,
StandardButton defaultButton = NoButton); int critical(QWidget *parent, const QString &title,
const QString &text, StandardButtons buttons = Ok,
StandardButton defaultButton = NoButton);
}; #endif // QMESSAGEBOXEX_H
源文件#include "qmessageboxex.h" static QMessageBoxEx *m_pThis = NULL;
QMessageBoxEx *QMessageBoxEx::shareQMessageBoxEx()
{
if (m_pThis == NULL)
m_pThis = new QMessageBoxEx();
return m_pThis;
} QMessageBoxEx::QMessageBoxEx()
{
} int QMessageBoxEx::information(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
{
this->setIcon(QMessageBox::Information);
this->setParent(parent);
this->setWindowTitle(title);
this->setText(text);
this->setStandardButtons(buttons);
this->setDefaultButton(defaultButton);
this->setWindowModality(Qt::WindowModal);
return this->exec();
} int QMessageBoxEx::question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
{
this->setIcon(QMessageBox::Question);
this->setParent(parent);
this->setWindowTitle(title);
this->setText(text);
this->setStandardButtons(buttons);
this->setDefaultButton(defaultButton);
this->setWindowModality(Qt::WindowModal);
return this->exec();
} int QMessageBoxEx::warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
{
this->setIcon(QMessageBox::Warning);
this->setParent(parent);
this->setWindowTitle(title);
this->setText(text);
this->setStandardButtons(buttons);
this->setDefaultButton(defaultButton);
this->setWindowModality(Qt::WindowModal);
return this->exec();
} int QMessageBoxEx::critical(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
{
this->setIcon(QMessageBox::Critical);
this->setParent(parent);
this->setWindowTitle(title);
this->setText(text);
this->setStandardButtons(buttons);
this->setDefaultButton(defaultButton);
this->setWindowModality(Qt::WindowModal);
return this->exec();
}
使用
调用事例 if (QMessageBox::Yes == QMessageBoxEx::shareQMessageBoxEx()->question(Dialog::shareDialog(),tr("Question"),tr("project folder is exists, will rename \"proj.qt.bak\" !"),
QMessageBox::Yes|QMessageBox::No,QMessageBox::No))
{
if (false == QDir(projectFileInfo.absoluteFilePath()).rename(qtProFileInfo.absoluteFilePath(),"proj.qt.bak"))
{
QMessageBoxEx::shareQMessageBoxEx()->critical(Dialog::shareDialog(),tr("Error"),tr("rename proj.qt failure"));
return;
}
}
预览

QMessageBox 在MAC下更加自然的更多相关文章
- 在MAC下搭建JSP开发环境
1.Mac下JDK的下载安装及配置 在安装jdk之后,需要为jdk安装目录配置环境变量: 任意打开终端,默认是家目录的,然后直接输入: touch .bash_profile 然后输入:vi .bas ...
- Mac下改动Android Studio 所用的JDK版本号
Mac下改动Android Studio 所用的JDK版本号 @author ASCE1885 近期项目从Eclipse+Ant构建模式转移到了Android Studio+Gradle构建模式.自然 ...
- MAC下Xcode配置opencv(2017.3.29最新实践,亲测可行)
本文原创,未经同意,谢绝转载!(转载请告知本人并且经过本人同意--By Pacific-hong) 本人小硕一枚,因为专业方向图像相关,所以用到opencv,然后网上MAC下Xcode配置opencv ...
- MAC下Xcode配置opencv(2017.3.29最新实践,亲测可行)(转)
本文原创,未经同意,谢绝转载!(转载请告知本人并且经过本人同意--By Pacific-hong) 本人小硕一枚,因为专业方向图像相关,所以用到opencv,然后网上MAC下Xcode配置opencv ...
- SQL语句:Mac 下 处理myql 不能远程登录和本地登录问题
mac下,mysql5.7.18连接出错,错误信息为:Access denied for user 'root'@'localhost' (using password: YES) ()里面的为she ...
- Mac下安装SQLmap的安装
1.cd /usr/bin/ 2.sudo git clone https://github.com/sqlmapproject/sqlmap.git sqlmap-dev3.重新打开terminal ...
- mac下安装及配置tomcat
mac下的软件不像windows下的程序那样写注册表,对于tomcat的安装来说,在mac下是名符其实的绿色软件,具体操作如下: 1.到 apache官方主页 下载完整 tar.gz文件包.(没有专门 ...
- MAC下 mysql不能插入中文和中文乱码的问题总结
MAC下 mysql不能插入中文和中文乱码的问题总结 前言 本文中所提到的问题解决方案,都是基于mac环境下的,但其他环境,比如windows应该也适用. 问题描述 本文解决下边两个问题: 往mysq ...
- 【开发软件】 在Mac下配置php开发环境:Apache+php+MySql
本文地址 原文地址 本文提纲: 1. 启动Apache 2. 运行PHP 3. 配置Mysql 4. 使用PHPMyAdmin 5. 附录 有问题请先 看最后的附录 摘要: 系统OS X ...
随机推荐
- BZOJ 3931: [CQOI2015]网络吞吐量 最大流
3931: [CQOI2015]网络吞吐量 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...
- 解决statusStrip控件上的项目不能靠右对齐的问题
在c#中用到了状态栏控件StatusStrip,但当我想把StatusStrip上某个StatusLabel靠右对齐时出了问题. 按照MSDN中的办法,是设置ToolStripStatusLabel的 ...
- 在安卓开发中使用SQLite数据库操作实例
前段时间写了个安卓平台下SQLite数据库操作的实例 ,一直没得时间总结 ,今天把它弄出来了. 在Android 运行时环境包含了完整的 SQLite. 首先介绍一下SQLite这个数据库: SQLi ...
- [Javascript] Other functor
EventStream: You can use RxJS, BaconJS or any reactive programming lib you want: var id_s = map(func ...
- SQL SERVER 查询Job作业基本信息及执行情况
查询作业基本信息和作业执行情况 SELECT [jop].[job_id] AS '作业唯一标识符' ,[jop].[ name ] AS '作业名称' ,[dp].[ name ] AS '作业创建 ...
- uboot_starts_analysis.pdf
Uboot中start.S源码的指令级的详尽解析 HTML版本的在线地址为:http://www.crifan.com/files/doc/docbook/uboot_starts_analysis/ ...
- 完全自定义 TabBar
// // CustomTabBarController.h // Dream // // Created by mac on 14-10-17. // Copyright (c) 2014年 HM. ...
- 动一动手指,玩转 Kindle Paperwhite 2 (2015.7.13)
Crtl+F 可搜索关键词.不(da)定(si)期(bu)更新,注明本帖链接即可转载.我可懒得写太详细,所以直接引了贴吧/论坛链接,这里衷心感谢原作. 首发贴吧,结果没几个人回复加上某度抽风难止就转移 ...
- nineOldAnimation 应用
Android动画学习笔记-Android Animation 3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中 ...
- Laravel_Elixir_gulp任务利器安装
目录 说明 安装 1安装gulp 2安装Elixir 3Elixir快速入门 4合并cssjs 5版本控制version 6复制copy 7方法串联 1.说明 详细说明暂时省略,后期补充.小白的角度理 ...