美文网首页
Qt学习笔记(六)对话框

Qt学习笔记(六)对话框

作者: 行走行囊 | 来源:发表于2018-04-18 21:24 被阅读0次

    1、对话框分类

    ①Modal 模式对话框:弹出后,背景界面卡主。
    ②Non-Modal 非模式对话框:背景界面可正常编辑。

    2、模式对话框(QDialog)

    主要有三个函数:

    accept()
    reject()
    exec()
    

    点击确定按钮后执行accept()会使得exec()返回Dialog::Accepted,点击取消按钮后执行reject(),exec()返回Dialog::Reject。

    3、文件对话框(QFileDialog)

    常用方法

    QString filePath = QFileDialog::getOpenFileName(
      this,// 父窗口
      GBK::ToUnicode("选择文件")// 窗口title
    )
    
    QString filePath = QFileDialog::getSaveFileName(
      this,// 父窗口
      GBK::ToUnicode("选择文件")// 窗口title
    )
    

    4、非模态窗口

    使用方法

    ①创建一个Widget派生类,作为非模态窗口。
    m_searchWindow = new MySearchWindow(this);
    m_searchWindow->setWindowFlags(Qt::Window);
    connect(ui.startSearchBtn, SIGNAL(clicked()), this, SLOT(SearchBtnClicked()));
    
    ②在父窗口中创建对象非模态窗口对象,在相应方法中执行显示动作。
    void MyWin3::SearchBtnClicked() {
        m_searchWindow->show();
    }
    

    相关文章

      网友评论

          本文标题:Qt学习笔记(六)对话框

          本文链接:https://www.haomeiwen.com/subject/lccmkftx.html