赞
踩
目录
一些常见的标准对话框包括:
一些常见的内置对话框包括:
自定义对话框的创建通常涉及以下几个步骤:
- #ifndef MYQDIALOG_H
- #define MYQDIALOG_H
-
- #include <QDialog>
- #include <QLineEdit>
- #include <QPushButton>
- #include <QCheckBox>
-
- class myQDialog : public QDialog
- {
- Q_OBJECT
- public:
- myQDialog();
-
- public slots:
- void ok_pushed()
- {
- //ok按下stat为true
- stat = true;
- close();
- }
-
-
- void setpass(bool flag)
- {
- if(!flag)
- le1->setEchoMode(QLineEdit::Password);
- else
- le1->setEchoMode(QLineEdit::Normal);
- }
-
-
- public:
- static int getstat()
- {
- myQDialog a;
- //a.setFixedSize(100, 100);
- a.exec();
-
- return a.stat;
- }
-
-
- private:
- QLineEdit *le, *le1;
- QPushButton *pb;
- QCheckBox *ck;
- bool checked;
-
- int stat; //标志,标志对话框是按下什么结束的
-
- };
-
- #endif // MYQDIALOG_H
- #ifndef WIDGET_H
- #define WIDGET_H
-
- #include <QWidget>
-
- class Widget : public QWidget
- {
- Q_OBJECT
-
- public:
- Widget(QWidget *parent = 0);
- ~Widget();
- };
-
- #endif // WIDGET_H
- #include "myqdialog.h"
- #include <QFormLayout>
-
- myQDialog::myQDialog()
- {
- le = new QLineEdit;
- le1 = new QLineEdit;
- pb = new QPushButton("登录");
- ck = new QCheckBox;
-
-
- QFormLayout *fbox = new QFormLayout;
- fbox->addRow("user", le);
- fbox->addRow("pawd", le1);
- fbox->addRow("show password", ck);
- fbox->addRow("", pb);
-
- setLayout(fbox);
-
- le1->setEchoMode(QLineEdit::Password); // 设置密码框为密码模式
-
- stat = false;
-
- connect(pb, SIGNAL(clicked(bool)), this, SLOT(ok_pushed()));
- connect(ck, SIGNAL(clicked(bool)), this, SLOT(setpass(bool)));
- }
- #include "widget.h"
- #include <QWidget>
- #include <QDialog>
- #include "myqdialog.h"
-
- Widget::Widget(QWidget *parent)
- : QWidget(parent)
- {
- #if 0
- myQDialog a;
- a.setFixedSize(100, 100);
- a.exec();
-
- if(a.stat)
- exit(0);
-
- #endif
-
- int s = myQDialog::getstat();
-
- if (!s)
- exit(0);
- }
-
- Widget::~Widget()
- {
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。