From a25b0e07fecc9376263bb03b92b8ac0a51af22e1 Mon Sep 17 00:00:00 2001 From: moyanj <1561515308@qq.com> Date: Sun, 8 Sep 2024 15:48:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interface/main.py | 12 +++++------- interface/setting.py | 9 +++++++++ main.py | 13 +++++++++---- 3 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 interface/setting.py diff --git a/interface/main.py b/interface/main.py index cba95d2..3c331bb 100644 --- a/interface/main.py +++ b/interface/main.py @@ -1,11 +1,9 @@ -from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget +from PyQt5.QtWidgets import QWidget +from qfluentwidgets import PushButton, VBoxLayout class MainWidget(QWidget): def __init__(self, title="主页"): super().__init__() - self.name = "11" - layout = QVBoxLayout() - button = QPushButton(title) - layout.addWidget(button) - self.setLayout(layout) - self.setWindowTitle(title) \ No newline at end of file + self.setWindowTitle(title) + PushButton(title, self) # 创建按钮并添加到布局 + self.setLayout(VBoxLayout(self)) # 设置布局 \ No newline at end of file diff --git a/interface/setting.py b/interface/setting.py new file mode 100644 index 0000000..abfd0fb --- /dev/null +++ b/interface/setting.py @@ -0,0 +1,9 @@ +from PyQt5.QtWidgets import QWidget +from qfluentwidgets import PushButton, VBoxLayout + +class SettingWidget(QWidget): + def __init__(self, title="设置"): + super().__init__() + self.setWindowTitle(title) + PushButton(title, self) # 创建按钮并添加到布局 + self.setLayout(VBoxLayout(self)) # 设置布局 \ No newline at end of file diff --git a/main.py b/main.py index 3400376..5d4cc0b 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,20 @@ import sys from PyQt5.QtWidgets import QApplication from qfluentwidgets import FluentWindow, Theme, setTheme -from interface.main import MainWidget from qfluentwidgets import FluentIcon as FIF +from interface.main import MainWidget +from interface.setting import SettingWidget class MainWindow(FluentWindow): def __init__(self): super().__init__() + self.setWindowTitle("HoYoCenter") setTheme(Theme.DARK) - self.id2obj = {"main": MainWidget()} + self.id2obj = { + "主页": [MainWidget(), FIF.HOME], + "设置": [SettingWidget(), FIF.SETTING] + } self.init_ui() def init_ui(self): @@ -18,8 +23,8 @@ class MainWindow(FluentWindow): def init_menu(self): self.navigationInterface.setExpandWidth(150) for name, obj in self.id2obj.items(): - obj.setObjectName(name) - self.addSubInterface(obj, FIF.HOME, name) + obj[0].setObjectName(name) + self.addSubInterface(obj[0], obj[1], name) def create_app(): app = QApplication(sys.argv)