Qt学习笔记(六)对话框

2018-04-18  本文已影响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();
}
上一篇下一篇

猜你喜欢

热点阅读