优化UI
This commit is contained in:
230
v1/main.py
230
v1/main.py
@@ -1,10 +1,11 @@
|
||||
import sys
|
||||
from PyQt5.QtWidgets import QApplication, QMainWindow, QStackedWidget, QHBoxLayout, QWidget
|
||||
from PyQt5.QtWidgets import QApplication, QMainWindow, QStackedWidget, QHBoxLayout, QWidget, QMessageBox
|
||||
from PyQt5.QtCore import Qt
|
||||
from views.login import LoginPage
|
||||
from views.nav import NavBar
|
||||
from views.app_center import AppCenter
|
||||
from views.home import Home
|
||||
from views.word_to_pdf import WordToPDFPage
|
||||
from views.app_center import AppCenter
|
||||
from views.history import HistoryPage
|
||||
from PyQt5.QtGui import QPalette, QColor
|
||||
|
||||
@@ -33,21 +34,29 @@ QLineEdit:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* 按钮通用样式 */
|
||||
/* ===== 按钮全局样式 ===== */
|
||||
QPushButton {
|
||||
background-color: #4f46e5;
|
||||
color: white;
|
||||
border-radius: 6px;
|
||||
padding: 8px 16px;
|
||||
border: none;
|
||||
min-height: 35px;
|
||||
border-radius: 8px; /* 增加圆角程度 */
|
||||
padding: 10px 16px;
|
||||
min-height: 40px; /* 增加高度 */
|
||||
font-weight: 500;
|
||||
transition: all 0.2s ease;
|
||||
border: none;
|
||||
outline: none; /* 防止点击时出现虚线边框 */
|
||||
}
|
||||
|
||||
QPushButton:hover {
|
||||
background-color: #4338ca;
|
||||
transform: translateY(-1px);
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
QPushButton:pressed {
|
||||
background-color: #3730a3;
|
||||
transform: translateY(0);
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
QPushButton:disabled {
|
||||
@@ -55,6 +64,94 @@ QPushButton:disabled {
|
||||
color: #a0aec0;
|
||||
}
|
||||
|
||||
/* 特殊按钮样式 */
|
||||
QPushButton#navBtn {
|
||||
text-align: left;
|
||||
padding: 12px 25px;
|
||||
color: #a0aec0;
|
||||
border-radius: 8px;
|
||||
margin: 5px 15px;
|
||||
font-size: 14px;
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
min-height: auto; /* 覆盖全局最小高度 */
|
||||
}
|
||||
|
||||
QPushButton#navBtn:hover {
|
||||
background-color: rgba(79, 70, 229, 0.1);
|
||||
color: #cbd5e0;
|
||||
}
|
||||
|
||||
QPushButton#navBtn.active {
|
||||
background-color: rgba(79, 70, 229, 0.15);
|
||||
color: #818cf8;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
QPushButton#logoutBtn {
|
||||
text-align: left;
|
||||
padding: 12px 25px;
|
||||
border-radius: 8px;
|
||||
margin: 5px 15px;
|
||||
font-size: 14px;
|
||||
color: #feb2b2;
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
min-height: auto; /* 覆盖全局最小高度 */
|
||||
}
|
||||
|
||||
QPushButton#logoutBtn:hover {
|
||||
color: #f56565;
|
||||
}
|
||||
|
||||
/* 操作按钮样式 */
|
||||
QPushButton#actionBtn {
|
||||
background-color: rgba(129, 140, 248, 0.1);
|
||||
color: #818cf8;
|
||||
border: 1px solid rgba(129, 140, 248, 0.2);
|
||||
min-height: auto; /* 覆盖全局最小高度 */
|
||||
}
|
||||
|
||||
QPushButton#actionBtn:hover {
|
||||
background-color: rgba(129, 140, 248, 0.2);
|
||||
}
|
||||
|
||||
QPushButton#retryBtn {
|
||||
background-color: rgba(251, 113, 133, 0.1);
|
||||
color: #fb7185;
|
||||
border: 1px solid rgba(251, 113, 133, 0.2);
|
||||
min-height: auto; /* 覆盖全局最小高度 */
|
||||
}
|
||||
|
||||
QPushButton#retryBtn:hover {
|
||||
background-color: rgba(251, 113, 133, 0.2);
|
||||
}
|
||||
|
||||
QPushButton#deleteBtn {
|
||||
background-color: rgba(120, 113, 108, 0.1);
|
||||
color: #a8a29e;
|
||||
border: 1px solid rgba(120, 113, 108, 0.2);
|
||||
min-height: auto; /* 覆盖全局最小高度 */
|
||||
}
|
||||
|
||||
QPushButton#deleteBtn:hover {
|
||||
background-color: rgba(120, 113, 108, 0.2);
|
||||
}
|
||||
|
||||
/* 卡片按钮样式 */
|
||||
QPushButton#appCardBtn {
|
||||
min-height: auto; /* 覆盖全局最小高度 */
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
/* 登录页面按钮 */
|
||||
QPushButton#loginBtn {
|
||||
min-height: auto; /* 覆盖全局最小高度 */
|
||||
min-width: 240px;
|
||||
padding: 14px 30px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
/* 列表控件 */
|
||||
QListWidget {
|
||||
background-color: #2d3748;
|
||||
@@ -110,42 +207,64 @@ QLabel {
|
||||
}
|
||||
|
||||
/* 菜单栏 */
|
||||
QMenuBar {
|
||||
/* 导航栏 */
|
||||
#navBar {
|
||||
background-color: #1a202c;
|
||||
color: #e2e8f0;
|
||||
border-bottom: 1px solid #2d3748;
|
||||
border-right: 1px solid #2d3748;
|
||||
}
|
||||
|
||||
QMenuBar::item {
|
||||
background-color: transparent;
|
||||
padding: 4px 10px;
|
||||
}
|
||||
|
||||
QMenuBar::item:selected {
|
||||
background-color: #4f46e5;
|
||||
color: white;
|
||||
}
|
||||
|
||||
QMenu {
|
||||
/* 用户卡片 */
|
||||
#userCard {
|
||||
background-color: #2d3748;
|
||||
border: 1px solid #4a5568;
|
||||
color: #e2e8f0;
|
||||
padding: 4px;
|
||||
border-radius: 8px;
|
||||
margin: 15px;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
QMenu::item {
|
||||
padding: 6px 30px 6px 20px;
|
||||
/* 导航按钮 */
|
||||
#navBtn {
|
||||
text-align: left;
|
||||
padding: 12px 25px;
|
||||
color: #a0aec0;
|
||||
border-radius: 8px;
|
||||
margin: 5px 15px;
|
||||
font-size: 14px;
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
}
|
||||
|
||||
QMenu::item:selected {
|
||||
background-color: #4f46e5;
|
||||
color: white;
|
||||
#navBtn:hover {
|
||||
background-color: rgba(79, 70, 229, 0.1);
|
||||
color: #cbd5e0;
|
||||
}
|
||||
|
||||
QMenu::separator {
|
||||
height: 1px;
|
||||
background: #4a5568;
|
||||
margin: 4px 8px;
|
||||
#navBtn.active {
|
||||
background-color: rgba(79, 70, 229, 0.15);
|
||||
color: #818cf8;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 退出按钮 */
|
||||
#logoutBtn {
|
||||
text-align: left;
|
||||
padding: 12px 25px;
|
||||
border-radius: 8px;
|
||||
margin: 5px 15px;
|
||||
font-size: 14px;
|
||||
color: #feb2b2;
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
}
|
||||
|
||||
#logoutBtn:hover {
|
||||
color: #f56565;
|
||||
}
|
||||
|
||||
/* 分割线 */
|
||||
QFrame[frameShape="4"] { /* HLine */
|
||||
background-color: #2d3748;
|
||||
margin: 10px 15px;
|
||||
max-height: 1px;
|
||||
}
|
||||
|
||||
/* 进度条 */
|
||||
@@ -251,6 +370,10 @@ class MainWindow(QMainWindow):
|
||||
self.login_page = LoginPage()
|
||||
self.login_page.login_success.connect(self.handle_login_success)
|
||||
|
||||
# 首页
|
||||
self.home = Home()
|
||||
self.home.app_selected.connect(self.handle_app_selected)
|
||||
|
||||
# 应用中心页
|
||||
self.app_center = AppCenter()
|
||||
self.app_center.app_selected.connect(self.handle_app_selected)
|
||||
@@ -268,6 +391,7 @@ class MainWindow(QMainWindow):
|
||||
# 添加页面
|
||||
self.stacked_pages.addWidget(self.login_page)
|
||||
self.stacked_pages.addWidget(self.app_center)
|
||||
self.stacked_pages.addWidget(self.home)
|
||||
self.stacked_pages.addWidget(self.word_to_pdf)
|
||||
self.stacked_pages.addWidget(self.history_page)
|
||||
self.stacked_pages.addWidget(self.settings_page)
|
||||
@@ -285,7 +409,7 @@ class MainWindow(QMainWindow):
|
||||
self.nav_bar.show()
|
||||
# 设置默认激活页
|
||||
self.nav_bar.set_active_nav("home")
|
||||
self.stacked_pages.setCurrentWidget(self.app_center)
|
||||
self.stacked_pages.setCurrentWidget(self.home)
|
||||
|
||||
def handle_logout(self):
|
||||
self.username = None
|
||||
@@ -298,6 +422,8 @@ class MainWindow(QMainWindow):
|
||||
|
||||
# 根据导航ID切换页面
|
||||
if nav_id == "home":
|
||||
self.stacked_pages.setCurrentWidget(self.home)
|
||||
if nav_id == "app_center":
|
||||
self.stacked_pages.setCurrentWidget(self.app_center)
|
||||
elif nav_id == "history":
|
||||
self.stacked_pages.setCurrentWidget(self.history_page)
|
||||
@@ -305,9 +431,35 @@ class MainWindow(QMainWindow):
|
||||
self.stacked_pages.setCurrentWidget(self.settings_page)
|
||||
|
||||
def handle_app_selected(self, app_id):
|
||||
if app_id == "word_to_pdf":
|
||||
self.stacked_pages.setCurrentWidget(self.word_to_pdf)
|
||||
# 后续可添加其他应用
|
||||
try:
|
||||
if app_id == "word_to_pdf":
|
||||
self.stacked_pages.setCurrentWidget(self.word_to_pdf)
|
||||
elif app_id == "history":
|
||||
# 注意:这里假设历史记录页面尚未开发,暂时显示word_to_pdf页面
|
||||
# 实际开发中应替换为正确的历史记录页面
|
||||
self.stacked_pages.setCurrentWidget(self.word_to_pdf)
|
||||
else:
|
||||
# 未开发的应用:弹出提示弹窗
|
||||
self.show_development_popup(app_id)
|
||||
except Exception as e:
|
||||
# 捕获并打印异常信息,避免程序闪退
|
||||
print(f"处理应用选择时发生错误: {e}")
|
||||
# 可以选择显示错误弹窗
|
||||
QMessageBox.critical(self, "错误", f"发生错误: {str(e)}", QMessageBox.Button.Ok)
|
||||
|
||||
def show_development_popup(self, app_id):
|
||||
"""显示开发中弹窗"""
|
||||
try:
|
||||
msg_box = QMessageBox(self)
|
||||
msg_box.setWindowTitle("功能开发中")
|
||||
msg_box.setText(f"应用 '{app_id}' 正在开发中")
|
||||
msg_box.setInformativeText("我们正在努力开发此功能,敬请期待!")
|
||||
msg_box.setIcon(QMessageBox.Icon.Information)
|
||||
msg_box.setStandardButtons(QMessageBox.Button.Ok)
|
||||
msg_box.button(QMessageBox.Button.Ok).setText("知道了")
|
||||
msg_box.exec()
|
||||
except Exception as e:
|
||||
print(f"显示弹窗时发生错误: {e}")
|
||||
|
||||
|
||||
def main():
|
||||
@@ -324,4 +476,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user