diff --git a/interface/main.py b/interface/main.py index 3c331bb..a271cf0 100644 --- a/interface/main.py +++ b/interface/main.py @@ -4,6 +4,6 @@ from qfluentwidgets import PushButton, VBoxLayout class MainWidget(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/interface/setting.py b/interface/setting.py index abfd0fb..0d4d8cd 100644 --- a/interface/setting.py +++ b/interface/setting.py @@ -1,9 +1,21 @@ -from PyQt5.QtWidgets import QWidget -from qfluentwidgets import PushButton, VBoxLayout +from PyQt5.QtWidgets import QWidget, QHBoxLayout +from qfluentwidgets import SwitchSettingCard +from qfluentwidgets import FluentIcon as FIF 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 + self.base = QHBoxLayout(self) + c1 = SwitchSettingCard(FIF.DEVELOPER_TOOLS, "调试模式") + c1.checkedChanged.connect(self.on_switch_changed) + self.base.addWidget(c1) + + self.setLayout(self.base) # 设置布局 + + def on_switch_changed(self, isChecked): + if isChecked: + print("调试模式已开启") + # 在这里添加开启调试模式的代码 + else: + print("调试模式已关闭") + # 在这里添加关闭调试模式的代码 diff --git a/main.py b/main.py index 5d4cc0b..0f6f7de 100644 --- a/main.py +++ b/main.py @@ -1,40 +1,61 @@ -import sys from PyQt5.QtWidgets import QApplication from qfluentwidgets import FluentWindow, Theme, setTheme from qfluentwidgets import FluentIcon as FIF + from interface.main import MainWidget from interface.setting import SettingWidget +import sys +# 主窗口类 class MainWindow(FluentWindow): def __init__(self): super().__init__() + # 设置窗口标题 self.setWindowTitle("HoYoCenter") - setTheme(Theme.DARK) + + setTheme(Theme.LIGHT) + + # 定义id和对象映射 self.id2obj = { "主页": [MainWidget(), FIF.HOME], "设置": [SettingWidget(), FIF.SETTING] } + # 初始化UI self.init_ui() def init_ui(self): + # 初始化菜单 self.init_menu() + # 初始化菜单 def init_menu(self): + # 设置导航栏展开宽度 self.navigationInterface.setExpandWidth(150) + # 遍历id和对象映射 for name, obj in self.id2obj.items(): + # 设置对象名称 obj[0].setObjectName(name) + # 添加子界面 self.addSubInterface(obj[0], obj[1], name) +# 创建应用程序 def create_app(): app = QApplication(sys.argv) window = MainWindow() + workaera = app.primaryScreen().availableGeometry() + # 设置窗口大小 + window.resize(workaera.width(),workaera.height()) + # 显示窗口 window.show() return app +# 主函数 def main(): app = create_app() + # 运行应用程序 sys.exit(app.exec_()) +# 如果是主程序运行 if __name__ == '__main__': main() \ No newline at end of file