main.cpp
#include "qdialogtest.h"
#include <QtWidgets/QApplication>
#include <QDebug>
#include "xmessagebox.h"
#include "progressbar.h"
#include "testprogressbar.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ProgressBar p;
TestProgressBar tp;
QObject::connect(&tp, SIGNAL(SetPos(int)), &p, SLOT(SetPos(int)));
tp.start();
p.exec();
QDialogTest w;
qDebug() << XMessageBox::info(QStringLiteral("测试新插入的提示"));
/* XMessageBox box;
box.exec();*/
int re = w.exec();
qDebug() << "re = " << re;
switch (re)
{
case QDialog::Accepted:
qDebug() << "Accepted";
break;
case QDialog::Rejected:
qDebug() << "Rejected";
break;
default:
qDebug() << re;
break;
}
// w.show();
return a.exec(); //处理信号与槽
}
progressbar.cpp
#include "progressbar.h"
#include <QThread>
ProgressBar::ProgressBar(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
//去掉标题栏
this->setWindowFlags(Qt::FramelessWindowHint);
//设置背景透明
this->setAttribute(Qt::WA_TranslucentBackground, true);
}
ProgressBar::~ProgressBar()
{
}
void ProgressBar::SetPos(int pos)
{
ui.progressBar->setValue(pos);
if (pos == 1000)
{
for (int i = 100; i > 0; i--)
{
this->setWindowOpacity((float)i/100.0); //设置透明度变大
QThread::msleep(10);
ui.label->setText(QString::number(i)); //显示透明度数值
QEventLoop loop; //处理所有事件
loop.processEvents();
}
this->close();
}
}
progressbar.h
#pragma once
#include <QDialog>
#include "ui_progressbar.h"
class ProgressBar : public QDialog
{
Q_OBJECT
public:
ProgressBar(QWidget *parent = Q_NULLPTR);
~ProgressBar();
public slots:
void SetPos(int);
private:
Ui::ProgressBar ui;
};
testprogressbar.cpp
#include "testprogressbar.h"
TestProgressBar::TestProgressBar()
: QThread()
{
}
TestProgressBar::~TestProgressBar()
{
}
void TestProgressBar::run()
{
for (int i = 0; i <= 1000; i++)
{
SetPos(i);
msleep(10);
}
}
testprogressbar.h
#include <QThread>
class TestProgressBar : public QThread
{
Q_OBJECT
public:
TestProgressBar();
~TestProgressBar();
void run();
signals:
void SetPos(int pos);
};
qdialogtest.cpp
#include "qdialogtest.h"
QDialogTest::QDialogTest(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
}
void QDialogTest::Test()
{
done(10);
}
qdialogtest.h
#pragma once
#include <QtWidgets/QDialog>
#include "ui_qdialogtest.h"
class QDialogTest : public QDialog
{
Q_OBJECT
public:
QDialogTest(QWidget *parent = Q_NULLPTR);
public slots:
void Test();
private:
Ui::QDialogTestClass ui;
};
xmessagebox.cpp
#include "xmessagebox.h"
XMessageBox::XMessageBox(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
//去掉标题栏
this->setWindowFlags(Qt::FramelessWindowHint);
//设置背景透明
this->setAttribute(Qt::WA_TranslucentBackground,true);
}
XMessageBox::~XMessageBox()
{
}
int XMessageBox::info(QString txt)
{
XMessageBox box;
box.ui.label->setText(txt);
return box.exec();
}
xmessagebox.h
#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;
};
ui_progressbar.h
/********************************************************************************
** Form generated from reading UI file 'progressbar.ui'
**
** Created by: Qt User Interface Compiler version 5.14.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_PROGRESSBAR_H
#define UI_PROGRESSBAR_H
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDialog>
#include <QtWidgets/QLabel>
#include <QtWidgets/QProgressBar>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_ProgressBar
{
public:
QWidget *widget;
QProgressBar *progressBar;
QLabel *label;
void setupUi(QDialog *ProgressBar)
{
if (ProgressBar->objectName().isEmpty())
ProgressBar->setObjectName(QString::fromUtf8("ProgressBar"));
ProgressBar->resize(400, 300);
widget = new QWidget(ProgressBar);
widget->setObjectName(QString::fromUtf8("widget"));
widget->setGeometry(QRect(0, 0, 400, 300));
widget->setStyleSheet(QString::fromUtf8("\n"
"background-color: qlineargradient(spread:reflect, x1:1, y1:0.477, x2:1, y2:1, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));"));
progressBar = new QProgressBar(widget);
progressBar->setObjectName(QString::fromUtf8("progressBar"));
progressBar->setGeometry(QRect(50, 170, 271, 61));
progressBar->setMaximum(1000);
progressBar->setValue(24);
label = new QLabel(widget);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(120, 90, 111, 31));
label->setStyleSheet(QString::fromUtf8("color: rgb(128, 255, 30);"));
label->setAlignment(Qt::AlignCenter);
retranslateUi(ProgressBar);
QMetaObject::connectSlotsByName(ProgressBar);
} // setupUi
void retranslateUi(QDialog *ProgressBar)
{
ProgressBar->setWindowTitle(QCoreApplication::translate("ProgressBar", "ProgressBar", nullptr));
label->setText(QString());
} // retranslateUi
};
namespace Ui {
class ProgressBar: public Ui_ProgressBar {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_PROGRESSBAR_H
ui_dialogtest.h
/********************************************************************************
** Form generated from reading UI file 'qdialogtest.ui'
**
** Created by: Qt User Interface Compiler version 5.14.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_QDIALOGTEST_H
#define UI_QDIALOGTEST_H
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDialog>
#include <QtWidgets/QPushButton>
QT_BEGIN_NAMESPACE
class Ui_QDialogTestClass
{
public:
QPushButton *okButton;
QPushButton *cancleButton;
QPushButton *doneButton;
void setupUi(QDialog *QDialogTestClass)
{
if (QDialogTestClass->objectName().isEmpty())
QDialogTestClass->setObjectName(QString::fromUtf8("QDialogTestClass"));
QDialogTestClass->resize(600, 400);
okButton = new QPushButton(QDialogTestClass);
okButton->setObjectName(QString::fromUtf8("okButton"));
okButton->setGeometry(QRect(120, 200, 93, 28));
cancleButton = new QPushButton(QDialogTestClass);
cancleButton->setObjectName(QString::fromUtf8("cancleButton"));
cancleButton->setGeometry(QRect(260, 200, 93, 28));
doneButton = new QPushButton(QDialogTestClass);
doneButton->setObjectName(QString::fromUtf8("doneButton"));
doneButton->setGeometry(QRect(190, 260, 93, 28));
retranslateUi(QDialogTestClass);
QObject::connect(okButton, SIGNAL(clicked()), QDialogTestClass, SLOT(accept()));
QObject::connect(cancleButton, SIGNAL(clicked()), QDialogTestClass, SLOT(reject()));
QObject::connect(doneButton, SIGNAL(clicked()), QDialogTestClass, SLOT(Test()));
QMetaObject::connectSlotsByName(QDialogTestClass);
} // setupUi
void retranslateUi(QDialog *QDialogTestClass)
{
QDialogTestClass->setWindowTitle(QCoreApplication::translate("QDialogTestClass", "QDialogTest", nullptr));
okButton->setText(QCoreApplication::translate("QDialogTestClass", "\347\241\256\350\256\244", nullptr));
cancleButton->setText(QCoreApplication::translate("QDialogTestClass", "\345\217\226\346\266\210", nullptr));
doneButton->setText(QCoreApplication::translate("QDialogTestClass", "Done", nullptr));
} // retranslateUi
};
namespace Ui {
class QDialogTestClass: public Ui_QDialogTestClass {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_QDIALOGTEST_H
ui_messagebox.h
/********************************************************************************
** Form generated from reading UI file 'xmessagebox.ui'
**
** Created by: Qt User Interface Compiler version 5.14.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_XMESSAGEBOX_H
#define UI_XMESSAGEBOX_H
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDialog>
#include <QtWidgets/QLabel>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_XMessageBox
{
public:
QWidget *widget;
QLabel *label;
QPushButton *okButton;
QPushButton *cancleButton;
void setupUi(QDialog *XMessageBox)
{
if (XMessageBox->objectName().isEmpty())
XMessageBox->setObjectName(QString::fromUtf8("XMessageBox"));
XMessageBox->resize(367, 300);
XMessageBox->setStyleSheet(QString::fromUtf8("QDialog{\n"
" border-radius:30;\n"
" background-color:rgb(204,204,204);\n"
" border: 1px solid gray;\n"
"}"));
widget = new QWidget(XMessageBox);
widget->setObjectName(QString::fromUtf8("widget"));
widget->setGeometry(QRect(0, 0, 367, 300));
widget->setStyleSheet(QString::fromUtf8("QWidget{\n"
" border-radius:30;\n"
" background-color:rgb(204,204,204);\n"
" border: 1px solid gray;\n"
"}"));
label = new QLabel(widget);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(10, 80, 331, 51));
label->setStyleSheet(QString::fromUtf8("font: 10pt \"\345\276\256\350\275\257\351\233\205\351\273\221\";"));
label->setAlignment(Qt::AlignCenter);
okButton = new QPushButton(widget);
okButton->setObjectName(QString::fromUtf8("okButton"));
okButton->setGeometry(QRect(40, 210, 93, 28));
okButton->setStyleSheet(QString::fromUtf8("background-color: qlineargradient(spread:reflect, x1:1, y1:0.472, x2:1, y2:1, stop:0.21393 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));\n"
"color: rgb(85, 255, 255);"));
cancleButton = new QPushButton(widget);
cancleButton->setObjectName(QString::fromUtf8("cancleButton"));
cancleButton->setGeometry(QRect(200, 210, 93, 28));
cancleButton->setStyleSheet(QString::fromUtf8("background-color: qlineargradient(spread:reflect, x1:1, y1:0.472, x2:1, y2:1, stop:0.21393 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));\n"
"color: rgb(85, 255, 255);"));
retranslateUi(XMessageBox);
QObject::connect(okButton, SIGNAL(clicked()), XMessageBox, SLOT(accept()));
QObject::connect(cancleButton, SIGNAL(clicked()), XMessageBox, SLOT(reject()));
QMetaObject::connectSlotsByName(XMessageBox);
} // setupUi
void retranslateUi(QDialog *XMessageBox)
{
XMessageBox->setWindowTitle(QCoreApplication::translate("XMessageBox", "XMessageBox", nullptr));
label->setText(QCoreApplication::translate("XMessageBox", "\346\265\213\350\257\225\346\266\210\346\201\257\346\225\210\346\236\234", nullptr));
okButton->setText(QCoreApplication::translate("XMessageBox", "\347\241\256\350\256\244", nullptr));
cancleButton->setText(QCoreApplication::translate("XMessageBox", "\345\217\226\346\266\210", nullptr));
} // retranslateUi
};
namespace Ui {
class XMessageBox: public Ui_XMessageBox {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_XMESSAGEBOX_H
ui_progressbar
ui_dialogtest
ui_messagebox