-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadingTipWidget.cpp
More file actions
49 lines (42 loc) · 1.32 KB
/
LoadingTipWidget.cpp
File metadata and controls
49 lines (42 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "stdafx.h"
#include "LoadingTipWidget.h"
#include <QVBoxLayout>
#include <QFont>
LoadingTipWidget::LoadingTipWidget(QWidget* parent)
: QWidget(parent), m_elapsedSeconds(0)
{
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
setAttribute(Qt::WA_TranslucentBackground);
setFixedSize(300, 100);
m_label = new QLabel(this);
m_label->setAlignment(Qt::AlignCenter);
m_label->setText(tr("加载模型中……0秒"));
m_label->setStyleSheet("color: white; background-color: rgba(0, 0, 0, 180); padding: 10px; border-radius: 10px;");
m_label->setFont(QFont("Microsoft YaHei", 14));
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(m_label);
setLayout(layout);
m_timer = new QTimer(this);
connect(m_timer, &QTimer::timeout, this, &LoadingTipWidget::updateTimer);
}
int LoadingTipWidget::exec()
{
m_elapsedSeconds = 0;
m_label->setText(tr("加载模型中……0秒"));
m_timer->start(1000);
show(); // 弹出窗口
m_eventLoop.exec(); // 阻塞,直到 stopAndClose() 被调用
return 0;
}
void LoadingTipWidget::updateTimer()
{
m_elapsedSeconds++;
m_label->setText(tr("加载模型中……%1秒").arg(m_elapsedSeconds));
}
void LoadingTipWidget::stopAndClose()
{
if (m_timer->isActive())
m_timer->stop();
close();
m_eventLoop.quit(); // 退出 exec 阻塞
}