QDialog 基本使用
QDialogTest w; //QDialogTest 继承自QDialog
int re = w.exec();
qDebug() << "re = " << re;
qDebug() << "result() = " << w.result();
switch (re)
{
case QDialog::Accepted:
qDebug() << "Accepted";
break;
case QDialog::Rejected:
qDebug() << "Rejected";
break;
default:
qDebug() << re;
break;
}
#pragma once
#include <QDialog>
#include "ui_xmessagebox.h"
class XMessageBox : public QDialog
{
Q_OBJECT
public:
XMessageBox(QWidget *parent = Q_NULLPTR);
~XMessageBox();
static int info(QString txt);
private:
Ui::XMessageBox ui;
};
#include "xmessagebox.h"
XMessageBox::XMessageBox(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
//去掉标题栏
this->setWindowFlags(Qt::FramelessWindowHint);
//设置背景透明 在QDialog内部设置与其长宽相同的QWidget作为背景容器
this->setAttribute(Qt::WA_TranslucentBackground, true);
}
XMessageBox::~XMessageBox()
{
}
int XMessageBox::info(QString txt)
{
XMessageBox box;
box.ui.label->setText(txt);
return box.exec();
}