对话框--QDialog(自定义对话框简单实例)
来源:互联网 发布:焦晃 北平无战事 知乎 编辑:程序博客网 时间:2024/06/04 18:12
//dialog.h头文件
#ifndef DIALOG_H
#define DIALOG_H
#include <QtGui/QDialog>
#include <QtGui/QtGui>
#include <QtCore/QTextCodec>
#include <QHBoxLayout>
class QLineEdit;
namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
public slots:
virtual void accept();
private:
QLineEdit * usrLineEdit;
QLineEdit * pwdLineEdit;
};
#endif // DIALOG_H
//dialog.cpp源文件
#include "dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent)
{
QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
QLabel *usrLabel = new QLabel(tr("用户名:"));
QLabel *pwdLabel = new QLabel(tr("密 码:"));
usrLineEdit = new QLineEdit;
pwdLineEdit = new QLineEdit;
pwdLineEdit->setEchoMode(QLineEdit::Password);
QGridLayout *gridLayout = new QGridLayout;
gridLayout->addWidget(usrLabel,0,0,1,1);
gridLayout->addWidget(pwdLabel,1,0,1,1);
gridLayout->addWidget(usrLineEdit,0,1,1,3);
gridLayout->addWidget(pwdLineEdit,1,1,1,3);
QPushButton *okBtn = new QPushButton(tr("确定"));
QPushButton *cancelBtn = new QPushButton(tr("取消"));
QHBoxLayout *btnLayout = new QHBoxLayout;
btnLayout->setSpacing(60);
btnLayout->addWidget(okBtn);
btnLayout->addWidget(cancelBtn);
QVBoxLayout *dlgLayout = new QVBoxLayout;
dlgLayout->setMargin(40);
dlgLayout->addLayout(gridLayout);
dlgLayout->addStretch(40);
dlgLayout->addLayout(btnLayout);
setLayout(dlgLayout);
connect(okBtn,SIGNAL(clicked()),this,SLOT(accept()));
connect(cancelBtn,SIGNAL(clicked()),this,SLOT(reject()));
setWindowTitle(tr("登录"));
resize(300,200);
}
Dialog::~Dialog()
{
}
void Dialog::accept()
{
if (usrLineEdit->text().trimmed() == tr("lcf") && pwdLineEdit->text() == tr("lcf"))
{
QDialog::accept();
}
else
{
QMessageBox::warning(this,tr("警告"),tr("用户名或密码错误"),QMessageBox::Yes);
usrLineEdit->setFocus();
}
}
//main.cpp主程序
#include <QtGui/QApplication>
#include "dialog.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog *dd = new Dialog;
dd->show();
return a.exec();
}
from:http://blog.sina.com.cn/s/blog_726c4bd201010oa4.html
0 0
- 对话框--QDialog(自定义对话框简单实例)
- 对话框 QDialog
- 对话框-QDialog
- Android简单对话框、输入对话框、单选对话框、复选对话框、列表对话框、自定义对话框、时间对话框
- QDialog 模态对话框与非模态对话框
- QDialog模态对话框与非模态对话框
- 【C2】对话框【S1】Subclassing QDialog
- Qt QDialog对话框 模态&非模态
- InstallShield创建自定义对话框 实例
- 常用对话框、自定义对话框
- 对话框之自定义对话框
- 对话框实例
- 2.1派生对话框类(Subclassing QDialog)
- 2.1派生对话框类(Subclassing QDialog)
- QDialog 模态对话框与事件循环
- QDialog 模态对话框与事件循环
- QDialog 模态对话框与事件循环
- QDialog 模态对话框与事件循环
- 大型Web应用开发总结
- The Balance(扩张欧几里得求线性方程ax+by=c或模线性方程ax=b (mod n)的完善模板)
- 20150824朴素贝叶斯.md
- Docker/compose分析
- 关于JDK配置环境变量的问题
- 对话框--QDialog(自定义对话框简单实例)
- Qt 常用类 (10)—— QDialog
- latex简历
- struct和typedef struct彻底明白了 && C语言结构体
- 简简单单讲sort--perl
- Linux下使用云笔记
- 《HTTP权威指南》阅读笔记(四)
- HDU 1856 并查集
- 公安部部署严打地下钱庄 深挖金融证券犯罪