from random import randint from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QWidget, QListWidgetItem, QLabel from .pc_decrypt import DecryptControl from .toolUI import Ui_Dialog from ...Ui.Icon import Icon # 美化样式表 Stylesheet = """ /*去掉item虚线边框*/ QListWidget, QListView, QTreeWidget, QTreeView { outline: 0px; border:none; background-color:rgb(240,240,240) } /*设置左侧选项的最小最大宽度,文字颜色和背景颜色*/ QListWidget { min-width: 400px; max-width: 400px; min-height: 80px; max-height: 80px; color: black; border:none; } QListWidget::item{ height:80px; width:80px; } /*被选中时的背景颜色和左边框颜色*/ QListWidget::item:selected { background: rgb(204, 204, 204); border-bottom: 4px solid rgb(9, 187, 7); border-left:none; color: black; font-weight: bold; } /*鼠标悬停颜色*/ HistoryPanel::item:hover { background: rgb(52, 52, 52); } """ class ToolWindow(QWidget, Ui_Dialog): def __init__(self, parent=None): super().__init__(parent) self.setupUi(self) self.setStyleSheet(Stylesheet) self.init_ui() def init_ui(self): self.listWidget.clear() self.listWidget.currentRowChanged.connect(self.setCurrentIndex) chat_item = QListWidgetItem(Icon.Chat_Icon, '解密', self.listWidget) contact_item = QListWidgetItem(Icon.Contact_Icon, 'None', self.listWidget) myinfo_item = QListWidgetItem(Icon.MyInfo_Icon, 'None', self.listWidget) tool_item = QListWidgetItem(Icon.MyInfo_Icon, 'None', self.listWidget) tool_window = DecryptControl() self.stackedWidget.addWidget(tool_window) label = QLabel('我是页面', self) label.setAlignment(Qt.AlignCenter) # 设置label的背景颜色(这里随机) # 这里加了一个margin边距(方便区分QStackedWidget和QLabel的颜色) label.setStyleSheet('background: rgb(%d, %d, %d);margin: 50px;' % ( randint(0, 255), randint(0, 255), randint(0, 255))) self.stackedWidget.addWidget(label) self.stackedWidget.addWidget(label) self.stackedWidget.addWidget(label) self.listWidget.setCurrentRow(0) self.stackedWidget.setCurrentIndex(0) def setCurrentIndex(self, row): print(row) self.stackedWidget.setCurrentIndex(row)