本文整理匯總了Python中qtpy.QtWidgets.QAction.setEnabled方法的典型用法代碼示例。如果您正苦於以下問題:Python QAction.setEnabled方法的具體用法?Python QAction.setEnabled怎麽用?Python QAction.setEnabled使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qtpy.QtWidgets.QAction
的用法示例。
在下文中一共展示了QAction.setEnabled方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ObjectExplorer
# 需要導入模塊: from qtpy.QtWidgets import QAction [as 別名]
# 或者: from qtpy.QtWidgets.QAction import setEnabled [as 別名]
#.........這裏部分代碼省略.........
if not index.isValid():
return
i = self.model().index(index.row(), 2, index.parent())
self.edit(i)
def insert_item(self):
index = self.currentIndex()
if index.isValid():
node = index.internalPointer()
else:
node = self.model().root
key, b = QInputDialog.getText(
self, "Insert Json item", "Insert key for new item:")
if not b:
return
item = JsonItem(key)
node.add(item)
row = node.index(item)
self.model().beginInsertRows(index, row, row)
self.model().endInsertRows()
def insert_node(self):
index = self.currentIndex()
parentnode = index.internalPointer() or self.model().root
key, b = QInputDialog.getText(
self, "Insert Json node", "Insert key for new node:")
if not b:
return
node = JsonNode(key)
parentnode.add(node)
row = parentnode.index(node)
self.model().beginInsertRows(index, row, row)
self.model().endInsertRows()
def mousePressEvent(self, event):
index = self.indexAt(event.pos())
if not index.isValid():
self.setCurrentIndex(QModelIndex())
super().mousePressEvent(event)
def refresh(self):
self.model().refresh()
def remove_item(self):
index = self.currentIndex()
self.model().beginRemoveRows(index.parent(), index.row(), index.row())
if index.isValid():
node = index.internalPointer()
if node.parent is not None:
node.parent.remove(node.key)
self.model().refresh()
self.model().endRemoveRows()
def show_contextmenu(self, pos: QPoint):
menu = QMenu(self)
index = self.currentIndex()
node = index.internalPointer()
# insert item and node
menu.addAction(self.insertitemAction)
menu.addAction(self.insertnodeAction)
# edit key
if isinstance(node, (JsonNode, JsonItem)):
menu.addSeparator()
menu.addAction(self.editkeyAction)
if isinstance(node, JsonItem):
menu.addAction(self.editAction)
self.editAction.setEnabled(not node.readonly)
# remove
if isinstance(node, (JsonNode, JsonItem)):
menu.addSeparator()
menu.addAction(self.removeitemAction)
# properties
if isinstance(node, JsonItem):
menu.addSeparator()
menu.addAction(self.propertiesAction)
menu.setDefaultAction(self.propertiesAction)
menu.popup(self.viewport().mapToGlobal(pos), self.editAction)
def show_properties(self):
index = self.currentIndex()
node = index.internalPointer()
if not (index.isValid() and isinstance(node, JsonItem)):
return
dlg = ItemPropertyDialog(node, self.parent())
if dlg.exec_() == QDialog.Accepted:
self.nodeproperty_changed.emit(node)
示例2: MainWindow
# 需要導入模塊: from qtpy.QtWidgets import QAction [as 別名]
# 或者: from qtpy.QtWidgets.QAction import setEnabled [as 別名]
#.........這裏部分代碼省略.........
self.saveasAction = QAction(self.tr("Save as..."), self)
self.saveasAction.setShortcut("Ctrl+Shift+S")
self.saveasAction.setIcon(QIcon(pixmap("document-save-as-5.png")))
self.saveasAction.triggered.connect(self.show_savecfg_dlg)
# Save file
self.saveAction = QAction(self.tr("Save"), self)
self.saveAction.setShortcut("Ctrl+S")
self.saveAction.setIcon(QIcon(pixmap("document-save-5.png")))
self.saveAction.triggered.connect(self.save_file)
# Load file
self.loadAction = QAction(self.tr("Open..."), self)
self.loadAction.setShortcut("Ctrl+O")
self.loadAction.setIcon(QIcon(pixmap("document-open-7.png")))
self.loadAction.triggered.connect(self.show_opencfg_dlg)
# New
self.newAction = QAction(self.tr("New"), self)
self.newAction.setShortcut("Ctrl+N")
self.newAction.setIcon(QIcon(pixmap("document-new-6.png")))
self.newAction.triggered.connect(self.new)
# start recording
self.startrecordingAction = QAction(self.tr("Start recording"), self)
self.startrecordingAction.setShortcut("F9")
self.startrecordingAction.setIcon(QIcon(pixmap("media-record-6.png")))
self.startrecordingAction.triggered.connect(self.start_recording)
# stop recording
self.stoprecordingAction = QAction(self.tr("Stop recording"), self)
self.stoprecordingAction.setShortcut("F10")
self.stoprecordingAction.setIcon(QIcon(pixmap("media-playback-stop-8.png")))
self.stoprecordingAction.setEnabled(False)
self.stoprecordingAction.triggered.connect(self.stop_recording)
# clear record
self.clearrecordAction = QAction(self.tr("Clear"), self)
self.clearrecordAction.setIcon(QIcon(pixmap("editclear.png")))
self.clearrecordAction.triggered.connect(self.clear_record)
# export record
self.exportcsvAction = QAction(self.tr("Export to csv..."), self)
self.exportcsvAction.setIcon(QIcon(pixmap("text_csv.png")))
self.exportcsvAction.triggered.connect(self.export_csv)
# show record settings
self.recordsettingsAction = QAction(self.tr("Settings..."), self)
self.recordsettingsAction.setIcon(QIcon(pixmap("configure.png")))
self.recordsettingsAction.triggered.connect(self.show_recordsettings)
# Info
self.infoAction = QAction(self.tr("Info"), self)
self.infoAction.setShortcut("F1")
self.infoAction.triggered.connect(self.show_info)
def _init_menus(self):
# file menu
self.fileMenu = self.menuBar().addMenu(self.tr("File"))
self.fileMenu.addAction(self.newAction)
self.fileMenu.addAction(self.loadAction)
self.fileMenu.addAction(self.saveAction)
self.fileMenu.addAction(self.saveasAction)
self.fileMenu.addSeparator()
self.fileMenu.addAction(self.connectAction)
self.fileMenu.addAction(self.serialdlgAction)