#include "BuiltinDialog.h"

#include <QtGui/QTextEdit>

#include <QtGui/QPushButton>

#include <QtGui/QFileDialog>

#include <QtGui/QFontDialog>

#include <QtGui/QColorDialog>

#include <QtGui/QPrintDialog>

#include <QtGui/QInputDialog>

#include <QtGui/QErrorMessage>

#include <QtGui/QProgressDialog>

#include <QtGui/QPageSetupDialog>

#include <QtGui/QGridLayout>

#include <QtGui/QPalette>

#include <QtGui/QColor>

#include <QtGui/QPrinter>

#include <QtGui/QApplication>

#include <QtDebug>

BuiltinDialog::BuiltinDialog(QWidget *parent) :

QDialog(parent) {

// Create widgets.

displayTextEdit = new QTextEdit();

showFileDialogButton = new QPushButton(QObject::tr("File Dialog"));

showFontDialogButton = new QPushButton(QObject::tr("Font Dialog"));

showColorDialogButton = new QPushButton(QObject::tr("Color Dialog"));

showPrintDialogButton = new QPushButton(QObject::tr("Print Dialog"));

showInputDialogButton = new QPushButton(QObject::tr("Input Dialog"));

showErrorDialogButton = new QPushButton(QObject::tr("Error Dialog"));

showProgressDialogButton = new QPushButton(QObject::tr("Progress Dialog"));

showPageSetupDialogButton = new QPushButton(

QObject::tr("Page Setup Dialog"));

// Lay out widgets.

QGridLayout *gridLayout = new QGridLayout();

gridLayout->addWidget(showFileDialogButton, 0, 0, 1, 1);

gridLayout->addWidget(showFontDialogButton, 0, 1, 1, 1);

gridLayout->addWidget(showColorDialogButton, 0, 2, 1, 1);

gridLayout->addWidget(showPrintDialogButton, 1, 0, 1, 1);

gridLayout->addWidget(showInputDialogButton, 1, 1, 1, 1);

gridLayout->addWidget(showErrorDialogButton, 1, 2, 1, 1);

gridLayout->addWidget(showProgressDialogButton, 2, 0, 1, 1);

gridLayout->addWidget(showPageSetupDialogButton, 2, 1, 1, 1);

gridLayout->addWidget(displayTextEdit, 3, 0, 3, 3);

setLayout(gridLayout);

// Connect signals and slots.

QObject::connect(showFileDialogButton, SIGNAL(clicked()), this, SLOT(

buttonsClicked()));

QObject::connect(showFontDialogButton, SIGNAL(clicked()), this, SLOT(

buttonsClicked()));

QObject::connect(showColorDialogButton, SIGNAL(clicked()), this, SLOT(

buttonsClicked()));

QObject::connect(showPrintDialogButton, SIGNAL(clicked()), this, SLOT(

buttonsClicked()));

QObject::connect(showInputDialogButton, SIGNAL(clicked()), this, SLOT(

buttonsClicked()));

QObject::connect(showErrorDialogButton, SIGNAL(clicked()), this, SLOT(

buttonsClicked()));

QObject::connect(showProgressDialogButton, SIGNAL(clicked()), this, SLOT(

buttonsClicked()));

QObject::connect(showPageSetupDialogButton, SIGNAL(clicked()), this, SLOT(

buttonsClicked()));

// Initialize.

setWindowTitle(QObject::tr("Builtin Dialogs"));

}

void BuiltinDialog::buttonsClicked() {

QPushButton *button = qobject_cast<QPushButton *> (sender());

if (button == showFileDialogButton) {

QString fileName = QFileDialog::getOpenFileName(this, QObject::tr(

"Open File"), QDir::home().path(), QObject::tr(

"Images(*.png *.jpg *.gif)"));

displayTextEdit->setText(fileName);

else if (button == showFontDialogButton) {

bool ok;

const QFont &font = QFontDialog::getFont(&ok, displayTextEdit->font(),

this);

if (ok) {

displayTextEdit->setFont(font);

}

else if (button == showColorDialogButton) {

QPalette palette = displayTextEdit->palette();

const QColor &color = QColorDialog::getColor(palette.color(

QPalette::Base), this);

if (color.isValid()) {

palette.setColor(QPalette::Base, color);

displayTextEdit->setPalette(palette);

}

else if (button == showPrintDialogButton) {

QPrinter printer;

QPrintDialog dialog(&printer, this);

dialog.setWindowTitle(QObject::tr("Print Dialog"));

if (QDialog::Accepted == dialog.exec()) {

displayTextEdit->setText("Printing file.....");

}

else if (button == showInputDialogButton) {

bool ok;

QString text = QInputDialog::getText(this, QObject::tr(

"Input User Name"), QObject::tr("User Name: "),

QLineEdit::Normal, QDir::home().dirName(), &ok);

if (ok && !text.isEmpty()) {

displayTextEdit->setText(text);

}

else if (button == showErrorDialogButton) {

QErrorMessage box(this);

box.setWindowTitle(QObject::tr("Error Message"));

box.showMessage(QObject::tr("There are errors XX."));

box.showMessage(QObject::tr("There are errors XX."));

box.showMessage(QObject::tr("There are errors XX."));

box.showMessage(QObject::tr("There are errors YY."));

box.exec();

else if (button == showProgressDialogButton) {

int maxValue = 10000;

QProgressDialog dialog(QObject::tr("Copying files..."), QObject::tr(

"Cancel"), 0, maxValue, this);

dialog.setWindowModality(Qt::WindowModal);

dialog.setWindowTitle(QObject::tr("Progress Dialog"));

dialog.show();

for (int i = 0; i < maxValue; ++i) {

dialog.setValue(i);

qApp->processEvents();

if (dialog.wasCanceled()) {

break;

}

qDebug() << i; // #include <QtDebug>

}

dialog.setValue(maxValue);

else if (button == showPageSetupDialogButton) {

QPrinter printer;

QPageSetupDialog dlg(&printer, this);

dlg.setWindowTitle(QObject::tr("Page Setup"));

if (QDialog::Accepted == dlg.exec()) {

displayTextEdit->setText("Page's properties are setupped.");

}

}

}

http://www.cppblog.com/biao/archive/2009/03/28/78105.html

Qt: 内建对话框(各种对话框都有了,且用到了qobject_cast解析sender的技术)的更多相关文章

  1. qt学习001之运行对话框

    使用QT实现Window下运行对话框 1.摆放控件 首先设置并摆放相应的对话框控件,并更改相应名称:        2.实现功能 1)在文本框中输入信息后,点击确定或回车可以运行系统中相应的程序: 点 ...

  2. QT+ 使用标准对话框+关于对话框+问题对话框+文件对话框

    #include "mainwindow.h" #include <QMenuBar> #include <QMenu> #include <QAct ...

  3. 18第一章 ASP.Net内建对象

    第一章        ASP.Net内建对象 第一章        ASP.Net内建对象 ASP.Net为保持用户的数据和信息,内建了许多对象,包括Application.Response.Requ ...

  4. Bash shell的内建命令:type

    type指令是用来观察指令时来自于外部指令还是内建在bash中的指令. type  [-tpa]  name 选项与参数: :不加任何选项与参数时,type会显示出name是外部指令还是bash内建指 ...

  5. javascript 对象初探 (四)--- 内建对象之旅之Array

     我们不要去纠结神马是内建对象,神马是內建构造器.到后来你们便会发现其实她们都是对象. Array()是一个构建数组的內建构造器函数: var arr = new Array(); 与下面的是等效的: ...

  6. MFC编程入门之十六(对话框:消息对话框)

    前面几节讲了属性页对话框,我们可以根据所讲内容方便的建立自己的属性页对话框.本节讲解Windows系统中最常用最简单的一类对话框--消息对话框. 我们在使用Windows系统的过程中经常会见到消息对话 ...

  7. javascript内建对象

    内建对象等价于内建构造器内建对象大致分为三类:数据封装类对象--Object.Array.Boolean.Number和String工具类对象--Math.Date.RegExp等用于提供遍历的对象错 ...

  8. Paip.最佳实践-- Buildin variale 内建变量 ,魔术变量,预定义变量,系统常量,系统变量 1

    Paip.最佳实践-- Buildin variale 内建变量 ,魔术变量,预定义变量,系统常量,系统变量 1.1.1       C++内建变量(__LINE__).... 1.1.2       ...

  9. [pyhton]python内建方法

    撸一遍python的内建方法 这样做的好处就是:我如果要完成一个功能的时候,如果能用内建方法完成,就用内建方法.这样可以提高效率,同时使自己的代码更加优雅.哎呦?那岂不是撸完就是python高手了?我 ...

随机推荐

  1. Java知识思维导图

    注:图片来源于网络,谢谢分享. 1 开发环境Java SDK 下载和安装2 环境变量的配置(path和classpath)3 编程基础 标识符命名规范4 Java数据类型5 运算符6 分支语句(if, ...

  2. SpringMVC中注解和非注解方式下的映射器和适配器总结

    1. 非注解方式 1.1 处理器适配器 上一节中使用的处理器适配器是:org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapte ...

  3. 编译php5.6

    没想到编译个LAMP这么麻烦又简单. 按照官网的做就可以了,只是我在CentOs下一直会提示出现这个错误 按照官网的安装方法:install 用下面的参数: ./configure --with-ap ...

  4. JQuery 解决 鼠标快速滑过后,会执行多次滑出的问题

    如果用slideToggle,鼠标快速滑过后,滑进滑出很多次,要解决这个问题,用stop(false,true) $(".Nav_L").hover(function () { $ ...

  5. 【winform】如何在DateTimePicker中显示时分秒

    1. 首先属性里面的Format属性value设置为Custom(默认为Long) 2. 对应的Custom属性value设置为yyyy-MM-dd HH:mm:ss

  6. 关于html5 -- plus Webview模块管理应用窗口界面

    Webview模块管理应用窗口界面,通过plus.webview可获取应用界面管理对象. 方法: all:获取所有的webview窗口 close:关闭webview窗口 create:创建新的web ...

  7. android.intent.action.MAIN 与 android.intent.category.LAUNCHER 的验证理解

    第一种情况:有MAIN,无LAUNCHER,程序列表中无图标 原因:android.intent.category.LAUNCHER决定应用程序是否显示在程序列表里  第二种情况:无MAIN,有LAU ...

  8. Linux学习系列之Linux入门(二)Vim学习

    第二篇 Vim学习 主要内容: 基本命令: 插件扩展: 参考资料: vim是一个命令控制的文本编辑器,可以完成几乎我们想要做的所有工作,除了Emacs几乎没有其他的工具能和它匹敌.官方网站是:http ...

  9. Linux进程间通信IPC学习笔记

    linux下的进程通信手段基本上是从Unix平台上的进程通信手段继承而来的.而对Unix发展做出重大贡献的两大主力AT&T的贝尔实验室及BSD(加州大学伯克利分校的伯克利软件发布中心)在进程间 ...

  10. 奖学金评分系统(系统分析与设计版与Delphi实现代码)

    一.系统规划 1.1 项目背景介绍 在奖学金评比过程中,学生综合测评是学校普遍采用的评比手段.对学生实施综合素质测评的目的在于正确评价学生的综合素质,为评奖学金提供依据,实现学生教育管理工作的标准化. ...