本文整理汇总了Python中PyQt5.QtWidgets.QDockWidget.setContextMenuPolicy方法的典型用法代码示例。如果您正苦于以下问题:Python QDockWidget.setContextMenuPolicy方法的具体用法?Python QDockWidget.setContextMenuPolicy怎么用?Python QDockWidget.setContextMenuPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QDockWidget
的用法示例。
在下文中一共展示了QDockWidget.setContextMenuPolicy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QDockWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QDockWidget import setContextMenuPolicy [as 别名]
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__()
self.setWindowTitle("RainbowBB")
self.setParent(parent)
self.initUI()
def initUI(self):
self.setStyleSheet("QCheckBox { background: palette(window); border-radius: 4px; padding: 2px; margin-right: 2px; }")
self.toolBar = QToolBar(self)
self.toolBar.setStyleSheet(stylesheet % (create_gradient("pastel"),))
self.toolBar.setMovable(False)
self.toolBar.setContextMenuPolicy(Qt.CustomContextMenu)
self.addToolBar(self.toolBar)
self.reverseBox = QCheckBox("&Reverse", self)
self.reverseBox.clicked.connect(lambda: self.updateGradient())
self.toolBar.addWidget(self.reverseBox)
self.byWordBox = QCheckBox("By &word", self)
self.toolBar.addWidget(self.byWordBox)
self.bounceBox = QCheckBox("&Bounce", self)
self.bounceBox.clicked.connect(lambda: self.updateGradient())
self.toolBar.addWidget(self.bounceBox)
self.sizeList = QComboBox(self)
self.sizeList.addItem("None")
for num in range(1, 8):
self.sizeList.addItem(str(num))
self.toolBar.addWidget(self.sizeList)
self.cycleList = QComboBox(self)
self.toolBar.addWidget(self.cycleList)
self.cycleList.currentIndexChanged.connect(self.updateGradient)
self.loadCycles()
self.convertButton = QPushButton("&Convert", self)
self.convertButton.clicked.connect(self.convert)
self.toolBar.addWidget(self.convertButton)
self.reloadButton = QPushButton("Reload", self)
self.reloadButton.setShortcut("Alt+Shift+R")
self.reloadButton.clicked.connect(self.loadCycles)
self.toolBar.addWidget(self.reloadButton)
self.inputDock = QDockWidget("Input", self)
self.inputDock.setFeatures(QDockWidget.NoDockWidgetFeatures)
self.inputDock.setContextMenuPolicy(Qt.CustomContextMenu)
self.addDockWidget(Qt.LeftDockWidgetArea, self.inputDock)
self.inputField = QTextEdit(self)
self.inputField.setAcceptRichText(False)
self.inputDock.setWidget(self.inputField)
self.outputField = QTextEdit(self)
self.outputField.setReadOnly(True)
self.setCentralWidget(self.outputField)
def updateGradient(self, index=None):
if not index:
index = self.cycleList.currentIndex()
self.toolBar.setStyleSheet(stylesheet % (create_gradient(self.cycleList.itemText(index), self.reverseBox.isChecked(), self.bounceBox.isChecked()),))
def loadCycles(self):
rainbowbb.load_cycles()
self.cycleList.clear()
self.cycleList.addItem("pastel")
for cycle in sorted(list(rainbowbb.cycles.keys())):
if cycle != "pastel":
self.cycleList.addItem(cycle)
def show(self):
self.setVisible(True)
self.inputField.setFocus()
def convert(self):
self.outputField.setPlainText(rainbowbb.size(rainbowbb.colorize(self.inputField.toPlainText(), self.cycleList.currentText(), self.reverseBox.isChecked(), not self.byWordBox.isChecked(), self.bounceBox.isChecked()), self.sizeList.currentText() if self.sizeList.currentText() != "None" else None))