Qt-对话框



- 模式与非模式对话框

区别:

模式对话框就是不处理它就没法处理父窗口,而非模式对话框就是不用先处理此对话框也可以处理父窗口。

dialog.show()                           // 是否为显示模式对话框根据modal属性的设置而定
dialog.exec()                            // 忽略modal属性,总显示为模式对话框
void setModal (bool modal)     // 设置true时,表示设置为模式对话框
bool isModal ()                         // 判断是否为模式对话框




- QMessageBox

#include <QMessageBox>

QMessageBox msgBox;
msgBox.setText(QObject::tr("message消息内容"));
msgBox.exec();

QMessageBox msgBox;
msgBox.setWindowTitle("确认重启设备");
msgBox.setText("确定现在重启系统吗?");
msgBox.setIcon(QMessageBox::Information);
msgBox.setWindowIcon(QIcon(":res/logo.jpg"));     // 不设置的话默认与父窗体相同
msgBox.exec();

------------------------------------------------------------------------

QMessageBox::about ( QWidget * parent, const QString & title, const QString & text )

QMessageBox::aboutQt ( QWidget * parent, const QString & title = QString() )

QMessageBox::critical ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )

QMessageBox::information ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )

QMessageBox::question ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )

QMessageBox::warning ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )

------------------------------------------------------------------------

- StandardButton examples

QMessageBox::Yes / QMessageBox::No

简单示例:
quint32 ret = QMessageBox::question(this,
                                    "确认是否重启",
                                    "确定现在重启系统吗?",
                                    QMessageBox::No,
                                    QMessageBox::Yes);

if (ret == QMessageBox::Yes)
{
    reboot();
}
...



- 打开文件对话框(QFileDialog)

#include <QFileDialog>

QString filePath = QFileDialog::getOpenFileName(this,
"Select files",                                        // 对话框标题
QDir::currentPath(),                                   // 默认路径
"File type description(*.fileType1 *.fileType2 ...);;All files(*.*)");

if (!filePath.isNull())
{
    ...
}

! 注意:用空格隔开文件类型(在同一下拉列表项中显示);“;;”后面的内容将会作为一个新的文件类型下拉列表项。



- QInputDialog

#include <QInputDialog>

#define PI_EXIT_PWD      "123456"

QInputDialog *inputDlg = new QInputDialog(this);
inputDlg->setInputMode(QInputDialog::TextInput);
inputDlg->setTextEchoMode(QLineEdit::Password);
inputDlg->setLabelText("请输入验证密码:");
int ret = inputDlg->exec();

if (ret == QInputDialog::Accepted)
{
    if (inputDlg->textValue() != PI_EXIT_PWD)
    {
        showCritical("密码不正确!");
        e->ignore();
    }
}
else if (ret == QInputDialog::Rejected)
{
    e->ignore();
}
...
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值