本文整理汇总了Python中PyQt5.QtWidgets.QAction.setData方法的典型用法代码示例。如果您正苦于以下问题:Python QAction.setData方法的具体用法?Python QAction.setData怎么用?Python QAction.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QAction
的用法示例。
在下文中一共展示了QAction.setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_tab_add_clicked
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def on_tab_add_clicked(self):
pos = QCursor.pos()
planets = self.world.get_planets()
# logger.debug('tab bar add clicked, cursor pos = ({0}, {1})'.format(pos.x(), pos.y()))
menu = QMenu(self)
# galaxy view
galaxy_action = QAction(menu)
galaxy_action.setText(self.tr('Add galaxy view'))
galaxy_action.setData(QVariant('galaxy'))
menu.addAction(galaxy_action)
# planets
menu.addSection(self.tr('-- Planet tabs: --'))
for planet in planets:
action = QAction(menu)
action.setText('{0} {1}'.format(planet.name, planet.coords.coords_str()))
action.setData(QVariant(planet.planet_id))
menu.addAction(action)
action_ret = menu.exec(pos)
if action_ret is not None:
# logger.debug('selected action data = {0}'.format(str(action_ret.data())))
if action_ret == galaxy_action:
logger.debug('action_ret == galaxy_action')
self.add_tab_for_galaxy()
return
# else consider this is planet widget
planet_id = int(action_ret.data())
self.on_request_open_planet_tab(planet_id)
示例2: generateViewMenu
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def generateViewMenu(self):
values = [
(self.tr("Nothing"), "Nothing"),
(self.tr("POV"), "POV"),
(self.tr("Label"), "Label"),
(self.tr("Progress"), "Progress"),
(self.tr("Compile"), "Compile"),
]
menus = [
(self.tr("Tree"), "Tree"),
(self.tr("Index cards"), "Cork"),
(self.tr("Outline"), "Outline")
]
submenus = {
"Tree": [
(self.tr("Icon color"), "Icon"),
(self.tr("Text color"), "Text"),
(self.tr("Background color"), "Background"),
],
"Cork": [
(self.tr("Icon"), "Icon"),
(self.tr("Text"), "Text"),
(self.tr("Background"), "Background"),
(self.tr("Border"), "Border"),
(self.tr("Corner"), "Corner"),
],
"Outline": [
(self.tr("Icon color"), "Icon"),
(self.tr("Text color"), "Text"),
(self.tr("Background color"), "Background"),
],
}
self.menuView.clear()
self.menuView.addMenu(self.menuMode)
self.menuView.addSeparator()
# print("Generating menus with", settings.viewSettings)
for mnu, mnud in menus:
m = QMenu(mnu, self.menuView)
for s, sd in submenus[mnud]:
m2 = QMenu(s, m)
agp = QActionGroup(m2)
for v, vd in values:
a = QAction(v, m)
a.setCheckable(True)
a.setData("{},{},{}".format(mnud, sd, vd))
if settings.viewSettings[mnud][sd] == vd:
a.setChecked(True)
a.triggered.connect(self.setViewSettingsAction, AUC)
agp.addAction(a)
m2.addAction(a)
m.addMenu(m2)
self.menuView.addMenu(m)
示例3: test_matches_actions_by_their_data
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def test_matches_actions_by_their_data(qt):
action = QAction(None)
action.setData("<data>")
matcher = matchers.with_data("<data>")
assert_that(matcher.matches(action), is_(True), "same data")
action.setData("<other data>")
assert_that(matcher.matches(action), is_(False), "different data")
示例4: node_context_menu
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def node_context_menu(self, point):
index = self.view.table_network.indexAt(point)
valid, node = self.model.table_model_data(index)
if self.model.app.parameters.expert_mode:
menu = QMenu()
open_in_browser = QAction(self.tr("Open in browser"), self)
open_in_browser.triggered.connect(self.open_node_in_browser)
open_in_browser.setData(node)
menu.addAction(open_in_browser)
# Show the context menu.
menu.exec_(QCursor.pos())
示例5: updateDevices
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def updateDevices(self):
for action in self.deviceGroup.actions():
self.deviceGroup.removeAction(action)
self.menuDevice.removeAction(action)
for device in self.devices:
action = QAction(device.name, self.menuDevice)
action.setCheckable(True)
action.setData(device)
self.menuDevice.addAction(action)
self.deviceGroup.addAction(action)
action.setChecked(True)
self.device = device
示例6: actions
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def actions(self):
actions = []
for i in range(LatestCollections.LatestCount):
key = self.__key(i)
fileName = self.settings.value(key)
if fileName:
title = Collection.fileNameToCollectionName(fileName)
act = QAction(title, self)
act.setData(fileName)
actions.append(act)
return actions
示例7: menu_add_action
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def menu_add_action(self, name, callback, data=None, shortcut=None, icon=None):
action = QAction(name, self)
if icon:
action.setIcon(icon)
if shortcut:
action.setShortcut(shortcut)
action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
if data:
action.setData(data)
action.triggered.connect(callback)
self.addAction(action)
self.menu.addAction(action)
示例8: _refreshMenu
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def _refreshMenu(self, menuEntry):
menu, fixedItemCount = menuEntry
for action in menu.actions()[fixedItemCount:]:
menu.removeAction(action)
for item in self._items:
action = QAction(item, menu)
action.setData(item)
action.triggered.connect(self.menuItemWasClicked)
menu.addAction(action)
menu.addSeparator()
action = QAction(tr("Clear List"), menu)
action.triggered.connect(self.clear)
menu.addAction(action)
示例9: createColorMenu
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def createColorMenu(self, slot, defaultColor):
colors = [Qt.black, Qt.white, Qt.red, Qt.blue, Qt.yellow]
names = ["black", "white", "red", "blue", "yellow"]
colorMenu = QMenu(self)
for color, name in zip(colors, names):
action = QAction(self.createColorIcon(color), name, self,
triggered=slot)
action.setData(QColor(color))
colorMenu.addAction(action)
if color == defaultColor:
colorMenu.setDefaultAction(action)
return colorMenu
示例10: createStandardContextMenu
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def createStandardContextMenu(self):
popup_menu = QTextEdit.createStandardContextMenu(self)
if not self.spellcheck:
return popup_menu
# Select the word under the cursor.
# But only if there is no selection (otherwise it's impossible to select more text to copy/cut)
cursor = self.textCursor()
if not cursor.hasSelection():
cursor.select(QTextCursor.WordUnderCursor)
self.setTextCursor(cursor)
# Check if the selected word is misspelled and offer spelling
# suggestions if it is.
if self._dict and cursor.hasSelection():
text = str(cursor.selectedText())
valid = self._dict.check(text)
selectedWord = cursor.selectedText()
if not valid:
spell_menu = QMenu(self.tr('Spelling Suggestions'), self)
spell_menu.setIcon(F.themeIcon("spelling"))
for word in self._dict.suggest(text):
action = self.SpellAction(word, spell_menu)
action.correct.connect(self.correctWord)
spell_menu.addAction(action)
# Only add the spelling suggests to the menu if there are
# suggestions.
if len(spell_menu.actions()) != 0:
popup_menu.insertSeparator(popup_menu.actions()[0])
# Adds: add to dictionary
addAction = QAction(self.tr("&Add to dictionary"), popup_menu)
addAction.setIcon(QIcon.fromTheme("list-add"))
addAction.triggered.connect(self.addWordToDict)
addAction.setData(selectedWord)
popup_menu.insertAction(popup_menu.actions()[0], addAction)
# Adds: suggestions
popup_menu.insertMenu(popup_menu.actions()[0], spell_menu)
# popup_menu.insertSeparator(popup_menu.actions()[0])
# If word was added to custom dict, give the possibility to remove it
elif valid and self._dict.is_added(selectedWord):
popup_menu.insertSeparator(popup_menu.actions()[0])
# Adds: remove from dictionary
rmAction = QAction(self.tr("&Remove from custom dictionary"), popup_menu)
rmAction.setIcon(QIcon.fromTheme("list-remove"))
rmAction.triggered.connect(self.rmWordFromDict)
rmAction.setData(selectedWord)
popup_menu.insertAction(popup_menu.actions()[0], rmAction)
return popup_menu
示例11: loadRecents
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def loadRecents(self):
sttgns = QSettings()
self.mw.menuRecents.setIcon(QIcon.fromTheme("folder-recent"))
if sttgns.contains("recentFiles"):
lst = sttgns.value("recentFiles")
self.mw.menuRecents.clear()
for f in [f for f in lst if os.path.exists(f)]:
name = os.path.split(f)[1]
a = QAction(name, self)
a.setData(f)
a.setStatusTip(f)
a.triggered.connect(self.loadRecentFile)
self.mw.menuRecents.addAction(a)
self.btnRecent.setMenu(self.mw.menuRecents)
示例12: updatePointMenu
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def updatePointMenu(self):
menu = self.sender()
menu.clear()
self.calcMarker = QgsVertexMarker(self.canvas)
self.calcMarker.setColor(QColor('black'))
self.calcMarker.setIconType(QgsVertexMarker.ICON_CROSS)
points = self.tvPointList.model().getPointList(True)
transform = QgsCoordinateTransform(self.wgs84, self.canvas.mapSettings().destinationCrs(), QgsProject.instance())
for coords in points:
point = transform.transform(coords['x'], coords['y'])
action = QAction('Punkt %d (%f,%f)' % (coords['id'], point.x(), point.y()), menu)
action.setData([point.x(), point.y()])
action.triggered.connect(self.addCalcPoint)
action.hovered.connect(self.showCalcPoint)
menu.addAction(action)
示例13: createActions
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def createActions(self):
self.openAct = QAction("&Open...", self, shortcut="Ctrl+O",
triggered=self.open)
for codec in self.codecs:
name = codec_name(codec)
action = QAction(name + '...', self, triggered=self.save)
action.setData(name)
self.saveAsActs.append(action)
self.exitAct = QAction("E&xit", self, shortcut="Ctrl+Q",
triggered=self.close)
self.aboutAct = QAction("&About", self, triggered=self.about)
self.aboutQtAct = QAction("About &Qt", self,
triggered=QApplication.instance().aboutQt)
示例14: on_main_window_start
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def on_main_window_start(main_window):
main_window.theme_menu = main_window.menuBar().addMenu(
main_window.tr('Themes'))
themes_directory = QFileInfo('themes')
if themes_directory.exists():
active_theme = ThemeManager.get_active_theme()
path = themes_directory.absoluteFilePath()
group_action = QActionGroup(main_window)
group_action.setExclusive(True)
for theme in os.listdir(path):
action = QAction(theme, main_window)
action.setData(theme)
action.setCheckable(True)
if theme == active_theme:
action.setChecked(True)
action.changed.connect(ThemeManager.wrapper(main_window))
group_action.addAction(action)
group_action.addAction(action)
main_window.theme_menu.addAction(action)
示例15: node_context_menu
# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setData [as 别名]
def node_context_menu(self, point):
index = self.table_network.indexAt(point)
model = self.table_network.model()
if index.isValid() and index.row() < model.rowCount(QModelIndex()):
source_index = model.mapToSource(index)
is_root_col = model.sourceModel().columns_types.index('is_root')
is_root_index = model.sourceModel().index(source_index.row(), is_root_col)
is_root = model.sourceModel().data(is_root_index, Qt.DisplayRole)
menu = QMenu()
if is_root:
unset_root = QAction(self.tr("Unset root node"), self)
unset_root.triggered.connect(self.unset_root_node)
unset_root.setData(self.community.network.root_node_index(source_index.row()))
if len(self.community.network.root_nodes) > 1:
menu.addAction(unset_root)
else:
set_root = QAction(self.tr("Set as root node"), self)
set_root.triggered.connect(self.set_root_node)
set_root.setData(self.community.network.nodes[source_index.row()])
menu.addAction(set_root)
if self.app.preferences['expert_mode']:
open_in_browser = QAction(self.tr("Open in browser"), self)
open_in_browser.triggered.connect(self.open_node_in_browser)
open_in_browser.setData(self.community.network.nodes[source_index.row()])
menu.addAction(open_in_browser)
# Show the context menu.
menu.exec_(QCursor.pos())