本文整理汇总了Python中PyQt5.QtWidgets.QMenuBar.setStyleSheet方法的典型用法代码示例。如果您正苦于以下问题:Python QMenuBar.setStyleSheet方法的具体用法?Python QMenuBar.setStyleSheet怎么用?Python QMenuBar.setStyleSheet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QMenuBar
的用法示例。
在下文中一共展示了QMenuBar.setStyleSheet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ViewSourceDialog
# 需要导入模块: from PyQt5.QtWidgets import QMenuBar [as 别名]
# 或者: from PyQt5.QtWidgets.QMenuBar import setStyleSheet [as 别名]
class ViewSourceDialog(QMainWindow):
closed = pyqtSignal(QObject)
def __init__(self, parent=None, title="Source"):
super(ViewSourceDialog, self).__init__()
self.setParent(parent)
self.menuBar = QMenuBar(self)
self.menuBar.setStyleSheet("""QMenuBar { background: transparent; border: 0; }
QMenuBar::item { background: transparent;
color: palette(window-text); }
QMenuBar::item:pressed { background: palette(highlight);
color: palette(highlighted-text); }""")
self.setMenuBar(self.menuBar)
self.text = ""
self.findFlag = None
self.fileMenu = QMenu(tr("&File"), self.menuBar)
self.menuBar.addMenu(self.fileMenu)
self.saveAsAction = QAction(tr("&Save As..."), self)
self.saveAsAction.setShortcut("Ctrl+S")
self.saveAsAction.triggered.connect(self.saveAs)
self.addAction(self.saveAsAction)
self.fileMenu.addAction(self.saveAsAction)
self.viewMenu = QMenu(tr("&View"), self.menuBar)
self.menuBar.addMenu(self.viewMenu)
self.findAction = QAction(tr("&Find..."), self)
self.findAction.setShortcut("Ctrl+F")
self.findAction.triggered.connect(self.find)
self.addAction(self.findAction)
self.viewMenu.addAction(self.findAction)
self.findNextAction = QAction(tr("Find Ne&xt"), self)
self.findNextAction.setShortcut("Ctrl+G")
self.findNextAction.triggered.connect(self.findNext)
self.addAction(self.findNextAction)
self.viewMenu.addAction(self.findNextAction)
self.findPreviousAction = QAction(tr("Find Pre&vious"), self)
self.findPreviousAction.setShortcut("Ctrl+Shift+G")
self.findPreviousAction.triggered.connect(self.findPrevious)
self.addAction(self.findPreviousAction)
self.viewMenu.addAction(self.findPreviousAction)
self.sourceView = SourceView(self)
self.sourceView.setReadOnly(True)
self.sourceView.setFontFamily("monospace")
self.setCentralWidget(self.sourceView)
closeWindowAction = QAction(self)
closeWindowAction.setShortcut("Ctrl+W")
closeWindowAction.triggered.connect(self.close)
self.addAction(closeWindowAction)
self.setWindowTitle(title)
self.resize(640, 480)
def closeEvent(self, ev):
super(ViewSourceDialog, self).closeEvent(ev)
self.deleteLater()
def saveAs(self):
fname = QFileDialog.getSaveFileName(None, tr("Save As..."), self.windowTitle() + ".txt", tr("Text files (*.txt)"))
if type(fname) is tuple:
fname = fname[0]
if fname:
g = str(self.sourceView.toPlainText())
f = open(fname, "w")
f.write(g)
f.close()
def find(self):
find = QInputDialog.getText(self, tr("Find"), tr("Search for:"), QLineEdit.Normal, self.text)
if find[1]:
self.text = find[0]
else:
self.text = ""
if self.findFlag:
self.sourceView.find(self.text, self.findFlag)
else:
self.sourceView.find(self.text)
def findNext(self, findFlag=None):
if not self.text:
self.find()
else:
self.findFlag = findFlag
if self.findFlag:
self.sourceView.find(self.text, self.findFlag)
else:
self.sourceView.find(self.text)
def findPrevious(self):
self.findNext(QTextDocument.FindBackward)
def setFindFlag(self):
if self.findReverseAction.isChecked():
self.findFlag = QTextDocument.FindBackward
else:
#.........这里部分代码省略.........