添加设置

This commit is contained in:
moyanj 2024-09-08 15:48:25 +08:00
parent 2a4ab55fc5
commit a25b0e07fe
3 changed files with 23 additions and 11 deletions

View File

@ -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): class MainWidget(QWidget):
def __init__(self, title="主页"): def __init__(self, title="主页"):
super().__init__() super().__init__()
self.name = "11" self.setWindowTitle(title)
layout = QVBoxLayout() PushButton(title, self) # 创建按钮并添加到布局
button = QPushButton(title) self.setLayout(VBoxLayout(self)) # 设置布局
layout.addWidget(button)
self.setLayout(layout)
self.setWindowTitle(title)

9
interface/setting.py Normal file
View File

@ -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)) # 设置布局

13
main.py
View File

@ -1,15 +1,20 @@
import sys import sys
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
from qfluentwidgets import FluentWindow, Theme, setTheme from qfluentwidgets import FluentWindow, Theme, setTheme
from interface.main import MainWidget
from qfluentwidgets import FluentIcon as FIF from qfluentwidgets import FluentIcon as FIF
from interface.main import MainWidget
from interface.setting import SettingWidget
class MainWindow(FluentWindow): class MainWindow(FluentWindow):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.setWindowTitle("HoYoCenter") self.setWindowTitle("HoYoCenter")
setTheme(Theme.DARK) setTheme(Theme.DARK)
self.id2obj = {"main": MainWidget()} self.id2obj = {
"主页": [MainWidget(), FIF.HOME],
"设置": [SettingWidget(), FIF.SETTING]
}
self.init_ui() self.init_ui()
def init_ui(self): def init_ui(self):
@ -18,8 +23,8 @@ class MainWindow(FluentWindow):
def init_menu(self): def init_menu(self):
self.navigationInterface.setExpandWidth(150) self.navigationInterface.setExpandWidth(150)
for name, obj in self.id2obj.items(): for name, obj in self.id2obj.items():
obj.setObjectName(name) obj[0].setObjectName(name)
self.addSubInterface(obj, FIF.HOME, name) self.addSubInterface(obj[0], obj[1], name)
def create_app(): def create_app():
app = QApplication(sys.argv) app = QApplication(sys.argv)