• 第四十五课、创建查找对话框------------------狄泰软件学院


    一、查找对话框

    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学习中的经典范例

     

  • 相关阅读:
    ios代码大全
    MYSQL数据库之如何在已经建立好表之后重构数据表
    关于cookie在一个页面设置但是在另外一个页面获取不到的原因
    cookie的那点事儿
    关于a标签不能调用js方法的小细节,你注意到了么?
    关于mysql预处理技术的一点小心得
    关于delete使用limit的一些注意事项
    DP1 等分连续1-N个数的划分种数
    Spring 编程式事务和声明式事务管理
    java https client信任所有证书
  • 原文地址:https://www.cnblogs.com/gui-lin/p/6419304.html
Copyright © 2020-2023  润新知