-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (50 loc) · 1.74 KB
/
Copy pathmain.cpp
File metadata and controls
56 lines (50 loc) · 1.74 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
50
51
52
53
54
55
56
/*
By : yzx
Time : 2024/8/28 上午 2:27:10
*/
#include "mainwindow.h"
#include <QApplication>
#include "src/getip.h"
#include <qdebug.h>
#include <qlabel.h>
#include <qboxlayout.h>
#include <qscreen.h>
// 思路:相当于显示桌面歌词,但显示的不是歌词,而是IP
// https://github.com/opennessgames/DesktopIP/
class DesktopIP : public QWidget
{
public:
DesktopIP(QWidget *parent = nullptr) : QWidget(parent)
{
// 设置窗口标志以保持在最上层
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
// 创建一个标签以显示IP地址(歌词)
QLabel *label = new QLabel(QString("平头网吧<br>" + getWIFIIP()), this);
label->setStyleSheet("background-color: rgba(0, 0, 0, 0.5); color: white; font-size: 20px; padding: 10px;");
// 设置文字居中对齐
label->setAlignment(Qt::AlignCenter);
// 设置布局
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(label);
setLayout(layout);
// 将窗口居中显示在屏幕上
QScreen *screen = QGuiApplication::primaryScreen();
if (screen) {
QRect screenGeometry = screen->geometry();
int screenWidth = screenGeometry.width();
int screenHeight = screenGeometry.height();
int widgetWidth = 300; // 窗口宽度
int widgetHeight = 100; // 窗口高度
setGeometry((screenWidth - widgetWidth) / 2, (screenHeight - widgetHeight) / 2, widgetWidth, widgetHeight);
}
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
DesktopIP ip;
ip.show();
return a.exec();
}