【发布时间】:2018-10-26 12:34:10
【问题描述】:
我试图让 qmenu 中的项目在悬停时变为灰色,就像我应用的融合样式表一样,它们在悬停时变为白色。不幸的是,我的样式表没有得到应用。 我搜索了,我发现我应该将“悬停”设置为“选中”,我这样做了,但没有任何变化。
from PyQt5.QtWidgets import (QWidget, QPushButton, QApplication, QMessageBox, QRadioButton, QMainWindow, QLabel, QListWidget, QListWidgetItem,
QDesktopWidget, QCheckBox, QPlainTextEdit, QHBoxLayout, QVBoxLayout, QGridLayout, QStackedWidget, QFormLayout, QMenu,
QComboBox, QScrollArea, QLineEdit, QGroupBox, QListView, QToolTip, QFileDialog, QTabWidget, QAction, QInputDialog)
from PyQt5.QtGui import QIcon, QFont, QRegExpValidator, QStandardItemModel, QStandardItem, QIcon
from PyQt5.QtCore import Qt, QRegExp, QModelIndex
class WindowGUI(QMainWindow):
def __init__(self, gui):
super().__init__()
self.initUI(gui)
def initUI(self, gui): #Initializing basic GUI
self.setGeometry(QDesktopWidget().screenGeometry())
self.showMaximized()
self.setWindowTitle("ScheduleO")
self.setWindowIcon(QIcon("icons/schedule.png"));
self.menu = self.menuBar()
self.SCHMenu = self.menu.addMenu("Schedule")
self.SCHFormat = QAction("New Schedule Format", self)
self.SCHApply = QAction("Apply Schedule Format...", self)
#This is where the issue is
self.menu.setStyleSheet("font: 12pt; background-color: white; QMenu.item.selected {color: gray}")
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setStyle("fusion")
userGUI = UserGUI() #It is not shown, but I have it in my code
windowGUI = WindowGUI(userGUI)
windowGUI.show()
sys.exit(app.exec_())
而且,当我尝试时
self.menu.setStyleSheet("QMenu {font: 12pt; background-color: white;}; QMenu.item.selected {color: gray}")
没有应用整个样式表
我的 QMenu 选择器有问题吗?
【问题讨论】:
标签: python pyqt hover selected qmenu