zoukankan      html  css  js  c++  java
  • 第四十五课、创建查找对话框------------------狄泰软件学院

    一、查找对话框

    1、查找对话框是应用程序中的常用部件

    (1)、目标:开发一个可以在不同项目间复用的查找对话框

    2、查找对话框的需求分析

    (1)、可复用软件部件

    (2)、查找文本框中指定字符串

    (3)、能够指定查找方向

    (4)、支持大小写敏感查找

    (5)、附加:点击关闭按钮后隐藏

    3、查找对话框的架构与设计

    4、查找对话框的界面布局

    #ifndef FINDDIALOG_H
    #define FINDDIALOG_H
    
    #include <QDialog>
    #include <QPushButton>
    #include <QLabel>
    #include <QLineEdit>
    #include <QRadioButton>
    #include <QCheckBox>
    #include <QHBoxLayout>
    #include <QGroupBox>
    #include <QGridLayout>
    
    class FindDialog : public QDialog
    {
        Q_OBJECT
    
    protected:
    
        QGridLayout m_gLayout;//注意要把声明放在组件之前,否则程序崩溃
        QGroupBox m_gBox;
        QHBoxLayout m_hLayout;
    
        QLabel m_findLabel;
        QLineEdit m_findLineEdit;
        QPushButton m_findButton;
        QCheckBox m_checkBox;
        QRadioButton m_forwardButton;
        QRadioButton m_backwardButton;
        QPushButton m_cancleButton;
    
    public:
        explicit FindDialog(QWidget *parent = 0);
        bool event(QEvent* e);
    
    
    };
    
    #endif // FINDDIALOG_H
    可复用查找对话框头文件
    #include "FindDialog.h"
    #include <QEvent>
    
    FindDialog::FindDialog(QWidget *parent) : QDialog(parent, Qt::WindowCloseButtonHint | Qt::Drawer)
    {
    
        setWindowTitle("查找");
        m_findLabel.setText("查找内容: ");
        m_findButton.setEnabled(false);
        m_findButton.setText("查找下一个");
        m_checkBox.setText("区分大小写");
        m_forwardButton.setText("向上");
        m_backwardButton.setChecked(true);
        m_backwardButton.setText("向下");
        m_cancleButton.setText("取消");
        m_gBox.setTitle("方向");
    
    
        m_hLayout.addWidget(&m_forwardButton);
        m_hLayout.addWidget(&m_backwardButton);
        m_gBox.setLayout(&m_hLayout);
    
        m_gLayout.setSpacing(10);
        m_gLayout.addWidget(&m_findLabel, 0, 0);
        m_gLayout.addWidget(&m_findLineEdit, 0, 1);
        m_gLayout.addWidget(&m_findButton, 0, 2);
        m_gLayout.addWidget(&m_checkBox, 1, 0);
        m_gLayout.addWidget(&m_gBox, 1, 1);
        m_gLayout.addWidget(&m_cancleButton, 1, 2);
    
        setLayout(&m_gLayout);
    
    }
    bool FindDialog::event(QEvent* e)
    {
        if(e->type()==QEvent::Close)
        {
            hide();
            return true;
        }
    
        return QDialog::event(e);
    
    }
    可复用查找对话框实现文件

    文本编辑器其它修改的地方

    头文件:

    UI文件:

    Slots.cpp

    二、小结

    (1)、查找对话框可以用作一个可复用的软件部件进行开发

    (2)、查找对话框继承自QDialog

    (3)、查找对话框的界面通过布局管理器相互嵌套完成

    (4)、查找对话框的设计与实现是GUI学习中的经典范例

     

  • 相关阅读:
    AutoCAD Map 3D 2013新功能视频中文版
    程序编辑SHP文件并应用更改到数据源
    从Mac远程控制Windows
    MapGuide Open Source 2.2从零开始视频教程(英文)
    更改VirtualBox中Mac OS的分辨率
    在Map 3D显示管理器中更改当前地图的名字
    无需格式转换直接发布DWG图纸到Autodesk Infrastructure Map Server(AIMS) 2013
    AIMS/MapGuide API二次开发从入门到精通视频课程系列1
    Map 3D中通过程序删除图层及数据源
    Autodesk Infrastructure Map Server(AIMS)/MapGuide API二次开发学习指南
  • 原文地址:https://www.cnblogs.com/gui-lin/p/6419304.html
Copyright © 2011-2022 走看看