建議你這樣試試看:
#ifndef QWAITTINGDIALOG_H
#define QWAITTINGDIALOG_H
#include <QDialog>
#include <QLabel>
#include <QThread>
#include <QTimer>
class QWaittingDialog : public QDialog
{
Q_OBJECT
public:
explicit QWaittingDialog(QWidget *parent = nullptr);
void Run(int nStartValue);
signals:
public slots:
void on_timer_timeout();
private:
QLabel* m_pLabel;
QTimer* m_pTimer;
int m_nStartValue;
// QWidget interface
protected:
void paintEvent(QPaintEvent* event);
};
#endif // QWAITTINGDIALOG_H
#include "QWaittingDialog.h"
#include <QPainter>
#include <QVBoxLayout>
QWaittingDialog::QWaittingDialog(QWidget *parent) : QDialog(parent)
, m_nStartValue(0)
{
setWindowFlags(Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint);
// 全透明
setAttribute(Qt::WA_TranslucentBackground);
QVBoxLayout* pVBoxLayout = new QVBoxLayout(this);
m_pLabel = new QLabel();
pVBoxLayout->addWidget(m_pLabel);
m_pLabel->setText("");
m_pLabel->setAlignment(Qt::AlignCenter);
QString strStyle = "QLabel{"
"font-family: \"Microsoft YaHei\";"
"font-size: 128px;"
"color: rgb(50, 50, 50, 180);"
"}";
m_pLabel->setStyleSheet(strStyle);
m_pTimer = new QTimer(this);
connect(m_pTimer, &QTimer::timeout, this, &QWaittingDialog::on_timer_timeout);
m_pTimer->setInterval(1000);
}
void QWaittingDialog::Run(int nStartValue)
{
m_pTimer->stop();
m_nStartValue = nStartValue;
QWidget* parent = parentWidget();
move(parent->pos());
resize(parent->rect().width(), parent->rect().height());
on_timer_timeout();
m_pTimer->start();
show();
}
void QWaittingDialog::on_timer_timeout()
{
if (m_nStartValue == 0)
{
m_pTimer->stop();
close();
return;
}
m_pLabel->setText(QString::number(m_nStartValue));
m_nStartValue--;
}
void QWaittingDialog::paintEvent(QPaintEvent* event)
{
// 避免鼠標(biāo)穿透
QPainter painter(this);
painter.fillRect(this->rect(), QColor(240, 240, 240, 1)); // 配合全透明屬性一起使用
}
這樣做的好處:
注意事項(xiàng):
絕對(duì)不行還想不想你小雞雞什么驚喜就等你繼續(xù)繼續(xù)那些你抽煙到哪巴西亞婦女節(jié)嘲笑你現(xiàn)金皆大歡喜經(jīng)濟(jì)系獨(dú)具匠心就像你說(shuō)的啊啊啊啊吧
首先你需要一個(gè)美工,幫你設(shè)計(jì)好看的UI樣式,或者自己設(shè)計(jì)也可以,
然后參照設(shè)計(jì)好的UI樣式,完成代碼的編寫(xiě),在設(shè)置代碼樣式前你需要知道這些控件的設(shè)置方法,比如一個(gè)QPushButton的背景色:紅色,前景設(shè)置白色,邊框黑色
QPushButton#evilButton {其他控件配置請(qǐng)參考Qt提供的幫助文檔:
http://doc.qt.io/qt-4.8/stylesheet-examples.html
相關(guān)推薦:
勞務(wù)外包公司資質(zhì)(勞務(wù)外包公司需要具備什么資質(zhì))
國(guó)有企業(yè)怎么進(jìn)行改制(中國(guó)國(guó)有企業(yè)改制的方式有哪些)