[Qt] Qt对话框 [2013-09-17更新]
来源:互联网 发布:查找英文文献的数据库 编辑:程序博客网 时间:2024/06/06 08:28
- 模式与非模式对话框
dialog.show() // 是否为显示模式对话框根据modal属性的设置而定
dialog.exec() // 忽略modal属性,总显示为模式对话框
void setModal (bool modal) // 设置true时,表示设置为模式对话框
bool isModal () // 判断是否为模式对话框
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
简单示例:
#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);
"确认是否重启",
"确定现在重启系统吗?",
QMessageBox::No,
QMessageBox::Yes);
if (ret == QMessageBox::Yes)
{
reboot();
}
{
reboot();
}
...
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();
}
...
- 打开文件对话框(QFileDialog)
#include <QFileDialog>
QString filePath = QFileDialog::getOpenFileName(this,
"Select files", // 对话框标题
QDir::currentPath(), // 默认路径
"File type description(*.fileType1 *.fileType2 ...);;All files(*.*)");
if (!filePath.isNull())
{
...
}
! 注意:用空格隔开文件类型(在同一下拉列表项中显示);“;;”后面的内容将会作为一个新的文件类型下拉列表项。
#include <QFileDialog>
QString filePath = QFileDialog::getOpenFileName(this,
"Select files", // 对话框标题
QDir::currentPath(), // 默认路径
"File type description(*.fileType1 *.fileType2 ...);;All files(*.*)");
if (!filePath.isNull())
{
...
}
! 注意:用空格隔开文件类型(在同一下拉列表项中显示);“;;”后面的内容将会作为一个新的文件类型下拉列表项。
- QInputDialog
#include <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();
}
...
- [Qt] Qt对话框 [2013-09-17更新]
- [Qt] Qt Creator 使用技巧 [2013-09-17更新]
- [Qt] Qt时间 [2013-09-02更新]
- Qt对话框
- QT 对话框
- Qt 对话框
- Qt 对话框
- Qt-对话框
- qt对话框
- QT对话框
- QT对话框
- [Qt] Qt程序发布 [2013-09-16更新]
- [Qt] Qt鼠标 [2013-08-13更新]
- [Qt] 事件过滤器 [2013-06-17更新]
- [Qt] 界面美化 [2013-06-17更新]
- [Qt] 界面美化 [2013-06-17更新]
- Qt学习之路(17): Qt标准对话框之QMessageBox
- Qt学习之路(17): Qt标准对话框之QMessageBox
- 黑马程序员 Hello World!
- Oracle 索引扫描的4种类型
- js Dom节点操作API
- Java程序员应该知道的10个调试技巧
- ArcGIS for javascript官网环境搭建
- [Qt] Qt对话框 [2013-09-17更新]
- MoveWindow和SetWindowPos之异同!
- @Override:加载项目的时候,带@Override的出错原因
- C++设计模式--职责链模式
- OnDraw和OnPaint函数的区别
- Windows下svn客户端和服务器的安装使用
- IOS atomic与nonatomic,assign,copy与retain的定义和区别
- SQL Server触发器创建、删除、修改、查看
- Android UI 之一步步教你自定义控件(自定义属性、合理设计onMeasure、合理设计onDraw等)