HoYoCenter/interface/init/__init__.py
moyanj 2aa7bccd8d 初始化窗口和关于窗口的小部件布局调整
在初始化窗口中,标题标签被移除,并用AboutWidget实例替换,以简化界面并提供重新设计的介绍视图。
2024-09-14 23:58:11 +08:00

58 lines
1.6 KiB
Python

from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QDesktopWidget
from PyQt5.QtCore import Qt
from qfluentwidgets import PushButton, SubtitleLabel, Theme, setTheme
import app.env as env
from .about import AboutWidget
class InitWindow(QWidget):
def __init__(self, main_window):
super().__init__()
self.window = main_window
if env.config.theme == "dark":
setTheme(Theme.DARK)
# 给窗口添加样式
self.setStyleSheet("background-color: #2E2E2E;")
else:
setTheme(Theme.LIGHT)
# 设置窗口大小
self.resize(800, 600)
# 设置窗口始终位于最上层
self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint)
# 居中显示
self.center_window()
# 初始化布局
self.layout = QVBoxLayout(self)
# 将组件添加到布局中
self.layout.addWidget(AboutWidget())
self.start_button = PushButton('开始')
self.start_button.clicked.connect(self.run)
self.layout.addWidget(self.start_button)
# 应用布局
self.setLayout(self.layout)
def center_window(self):
"""将窗口居中显示"""
screen = QDesktopWidget().screenGeometry()
size = self.geometry()
new_left = (screen.width() - size.width()) // 2
new_top = (screen.height() - size.height()) // 2
self.move(new_left, new_top)
def run(self):
self.window.show()
self.close()
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
window = InitWindow()
window.show()
sys.exit(app.exec_())