zoukankan      html  css  js  c++  java
  • 第二十一课、Qt中的标准对话框(下)------------------狄泰软件学院

    一、字体对话框

    1、Qt提供了预定义的字体对话框QFontDialog类

    2、QFontDialog类用于提供选择字体的对话框部件

    3、字体对话框的使用方式

    4、字体对话框中的实用函数

    二、进度对话框

    1、Qt提供了预定义的进度对话框QProgressDialog类

    2、QProgressDialog类用于显示进度信息

    3、QProgressDialog类用于需要用户等待的场合

    4、进度对话框的使用方式

    三、打印对话框

    1、Qt中提供了预定义的打印对话框QPrintDialog类

    2、QPrintDialog类用于设置打印相关的参数信息

    3、打印对话框的使用方式

    4、Qt中的QPrinter类打印设备及其参数的封装

    5、QPrinter类封装了系统中打印设备的驱动接口

    6、QPrinter类以相同的方式使用系统中不同的打印设备

    #ifndef _WIDGET_H_
    #define _WIDGET_H_
    
    #include <QWidget>
    #include <QPushButton>
    
    class Widget : public QWidget
    {
        Q_OBJECT
    private:
        QPushButton FontDialogBtn;
        QPushButton ProgressDialogBtn;
        QPushButton PrintDialogBtn;
    
    private slots:
        void FontDialogBtn_Clicked();
        void ProgressDialogBtn_Clicked();
        void PrintDialogBtn_Clicked();
    
    public:
        Widget(QWidget* parent = 0);
        ~Widget();
    };
    
    #endif  //_WIDGET_H_
    Widget.h
    #include "Widget.h"
    #include <QFontDialog>
    #include <QPrintDialog>
    #include <QPrinter>
    #include <QTextDocument>
    #include <QProgressDialog>
    #include <QDebug>
    
    Widget::Widget(QWidget* parent):QWidget(parent),
         FontDialogBtn(this),ProgressDialogBtn(this),PrintDialogBtn(this)
    {
        FontDialogBtn.setText("Font Dialog");
        FontDialogBtn.move(20, 20);
        FontDialogBtn.resize(160, 30);
    
        ProgressDialogBtn.setText("Progress Dialog");
        ProgressDialogBtn.move(20, 70);
        ProgressDialogBtn.resize(160, 30);
    
        PrintDialogBtn.setText("Print Dialog");
        PrintDialogBtn.move(20, 120);
        PrintDialogBtn.resize(160, 30);
    
        resize(200, 170);
        setFixedSize(200, 170);
    
        connect(&FontDialogBtn,     SIGNAL(clicked()), this, SLOT(FontDialogBtn_Clicked()));
        connect(&ProgressDialogBtn, SIGNAL(clicked()), this, SLOT(ProgressDialogBtn_Clicked()));
        connect(&PrintDialogBtn,    SIGNAL(clicked()), this, SLOT(PrintDialogBtn_Clicked()));
    }
    
    
    void Widget::FontDialogBtn_Clicked()//与颜色对话框用法一样
    {
        QFontDialog dlg(this);//1.定义
    
        dlg.setWindowTitle("QFontDialog");//2.设置
        dlg.setCurrentFont(QFont("Courier New", 10, QFont::Bold));//设置初始字体,参数是调用字体设置的构造函数
    
        if(dlg.exec() == QDialog::Accepted)//3.显示
        {
            qDebug() << dlg.selectedFont();
        }
    }
    
    void Widget::ProgressDialogBtn_Clicked()//依旧是三板斧
    {
        QProgressDialog dlg(this);
    
        dlg.setWindowTitle("QProgressDialog");
        dlg.setLabelText("Dowload...");
        dlg.setMinimum(0);
        dlg.setMaximum(100);
    
        dlg.setValue(30);//设置当前进度框的位置
        //实际应用时,会开一个线程来进行下载东西,然后久不久调用setValue()函数一次
    
        dlg.exec();//没有if语句的原因是进度条对话框一般就是让人等待的
    
    }
    
    void Widget::PrintDialogBtn_Clicked()
    {
        QPrintDialog dlg(this);
    
        dlg.setWindowTitle("QPrintDialog");
    
        if(dlg.exec() == QPrintDialog::Accepted)
        {
            QPrinter* p = dlg.printer();//将参数设置进打印机
            QTextDocument tb;
            tb.setPlainText("Hello Qt");
    
            p->setOutputFileName("D:\Hello.pdf");
    
            tb.print(p);
        }
    }
    
    Widget::~Widget()
    {
    
    }
    Widget.cpp
    #include <QtGui/QApplication>
    #include "Widget.h"
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        Widget w;
        w.show();
        
        return a.exec();
    }
    main.cpp

    四、小结

    1、Qt中标准对话框的设计模式

    (1)、GUI界面产生数据对象

    (2)、业务逻辑中其它对象使用数据对象

    (3)、GUI界面业务逻辑通过数据对象连接

     

  • 相关阅读:
    java_oop_方法2
    POJ 3276 Face The Right Way(反转)
    POJ 3276 Face The Right Way(反转)
    POJ 2566 Bound Found(尺取法,前缀和)
    POJ 2566 Bound Found(尺取法,前缀和)
    POJ 3320 Jessica's Reading Problem(尺取法)
    POJ 3320 Jessica's Reading Problem(尺取法)
    POJ 3061 Subsequence(尺取法)
    POJ 3061 Subsequence(尺取法)
    HDU 1222 Wolf and Rabbit(欧几里得)
  • 原文地址:https://www.cnblogs.com/gui-lin/p/6403362.html
Copyright © 2011-2022 走看看