文章目录
1 文本编辑器实现关于对话框的功能1 文本编辑器实现关于对话框的功能
关于对话框:
标准的桌面应用软件都有一个关于对话框。关于对话框用于标识软件自身的信息: 软件Logo、项目名、版本号。开发者信息。版权信息。联系方式。
经典设计方案:
AboutDialog:
#ifndef _ABOUTDIALOG_H_#define _ABOUTDIALOG_H_#include <QDialog>#include <QLabel>#include <QPlainTextEdit>#include <QPushButton>class AboutDialog : public QDialog{Q_OBJECTQLabel m_logoLbl;QLabel m_qqLbl;QPlainTextEdit m_infoEdit;QPushButton m_closeBtn;public:explicit AboutDialog(QWidget *parent = 0);};#endif // _ABOUTDIALOG_H_
AbouDialog.cpp:
#include "AboutDialog.h"#include <QPixmap>#include <QPalette>AboutDialog::AboutDialog(QWidget *parent) :QDialog(parent, Qt::WindowCloseButtonHint), m_logoLbl(this), m_qqLbl(this), m_infoEdit(this), m_closeBtn(this){QPixmap pm(":/res/pic/dt.png");pm = pm.scaled(120, 120, Qt::KeepAspectRatio);m_logoLbl.setPixmap(pm);m_logoLbl.move(20, 20);m_logoLbl.resize(120, 120);QPalette p = m_infoEdit.palette();p.setColor(QPalette::Active, QPalette::Base, palette().color(QPalette::Active, QPalette::Background));p.setColor(QPalette::Inactive, QPalette::Base, palette().color(QPalette::Inactive, QPalette::Background));m_infoEdit.move(200, 30);m_infoEdit.resize(180, 130);m_infoEdit.setPalette(p);m_infoEdit.setFrameStyle(QFrame::NoFrame);m_infoEdit.setReadOnly(true);m_infoEdit.insertPlainText("NotePad Project\n\nPlatform: Qt 4.7.4\n\nVersion: 1.0.0\n\nCopyright: D.T.Software");m_qqLbl.move(22, 184);m_qqLbl.setText("QQ Group: 199546072");m_closeBtn.setText("Close");m_closeBtn.move(273, 175);m_closeBtn.resize(100, 30);setFixedSize(390, 230);setWindowTitle("About NotePad");connect(&m_closeBtn, SIGNAL(clicked()), this, SLOT(close()));}
槽函数的绑定:
槽函数的实现:
void MainWindow::onHelpAbout(){AboutDialog(this).exec();}
参考资料:
QT实验分析教程