初步实现设置界面
This commit is contained in:
parent
a25b0e07fe
commit
6d93c035b8
|
@ -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)) # 设置布局
|
|
@ -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)) # 设置布局
|
||||
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("调试模式已关闭")
|
||||
# 在这里添加关闭调试模式的代码
|
||||
|
|
25
main.py
25
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()
|
Loading…
Reference in New Issue
Block a user