当前位置: 首页>>代码示例>>Python>>正文


Python QAction.setIcon方法代码示例

本文整理汇总了Python中qtpy.QtWidgets.QAction.setIcon方法的典型用法代码示例。如果您正苦于以下问题:Python QAction.setIcon方法的具体用法?Python QAction.setIcon怎么用?Python QAction.setIcon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qtpy.QtWidgets.QAction的用法示例。


在下文中一共展示了QAction.setIcon方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: func_wrapper

# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setIcon [as 别名]
            def func_wrapper(plugin, workspace, *args, **kwargs):
                """
                Wrapper function that, when called, causes the plugin to be
                loaded into a specific workspace.
                """

                if workspace is None:
                    return

                if workspace.current_plot_window is None:
                    return

                parent = workspace.current_plot_window.tool_bar
                action = QAction(parent)

                action.setText(name)

                if icon is not None:
                    action.setIcon(icon)

                if location is not None and isinstance(location, str):
                    for level in location.split('/'):
                        parent = self.get_action(parent, level)

                before_action = [x for x in parent.actions()
                                 if x.isSeparator()].pop(-2)
                parent.insertAction(before_action, action)
                action.triggered.connect(lambda: func(plugin, *args, **kwargs))
开发者ID:nmearl,项目名称:specviz,代码行数:30,代码来源:plugin.py

示例2: create_action

# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setIcon [as 别名]
def create_action(parent, text, shortcut=None, icon=None, tip=None,
                  toggled=None, triggered=None, data=None, menurole=None,
                  context=Qt.WindowShortcut):
    """Create a QAction"""
    action = QAction(text, parent)
    if triggered is not None:
        action.triggered.connect(triggered)
    if toggled is not None:
        action.toggled.connect(toggled)
        action.setCheckable(True)
    if icon is not None:
        if is_text_string(icon):
            icon = get_icon(icon)
        action.setIcon(icon)
    if shortcut is not None:
        action.setShortcut(shortcut)
    if tip is not None:
        action.setToolTip(tip)
        action.setStatusTip(tip)
    if data is not None:
        action.setData(to_qvariant(data))
    if menurole is not None:
        action.setMenuRole(menurole)
    #TODO: Hard-code all shortcuts and choose context=Qt.WidgetShortcut
    # (this will avoid calling shortcuts from another dockwidget
    #  since the context thing doesn't work quite well with these widgets)
    action.setShortcutContext(context)
    return action
开发者ID:DLlearn,项目名称:spyder,代码行数:30,代码来源:qthelpers.py

示例3: create_action

# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setIcon [as 别名]
def create_action(parent, text, shortcut=None, icon=None, tip=None,
                  toggled=None, triggered=None, data=None, menurole=None,
                  context=Qt.WindowShortcut):
    """Create a QAction"""
    action = QAction(text, parent)
    if triggered is not None:
        action.triggered.connect(triggered)
    if toggled is not None:
        action.toggled.connect(toggled)
        action.setCheckable(True)
    if icon is not None:
        if is_text_string(icon):
            icon = get_icon(icon)
        action.setIcon(icon)
    if tip is not None:
        action.setToolTip(tip)
        action.setStatusTip(tip)
    if data is not None:
        action.setData(to_qvariant(data))
    if menurole is not None:
        action.setMenuRole(menurole)

    # Workround for Mac because setting context=Qt.WidgetShortcut
    # there doesn't have any effect
    if sys.platform == 'darwin':
        action._shown_shortcut = None
        if context == Qt.WidgetShortcut:
            if shortcut is not None:
                action._shown_shortcut = shortcut
            else:
                # This is going to be filled by
                # main.register_shortcut
                action._shown_shortcut = 'missing'
        else:
            if shortcut is not None:
                action.setShortcut(shortcut)
            action.setShortcutContext(context)
    else:
        if shortcut is not None:
            action.setShortcut(shortcut)
        action.setShortcutContext(context)

    return action
开发者ID:G-VAR,项目名称:spyder,代码行数:45,代码来源:qthelpers.py

示例4: SpyderAction

# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setIcon [as 别名]
class SpyderAction(QAction):
    """Spyder QAction class wrapper to handle cross platform patches."""

    def __init__(self, *args, **kwargs):
        """Spyder QAction class wrapper to handle cross platform patches."""
        super(SpyderAction, self).__init__(*args, **kwargs)
        self._action_no_icon = None

        if sys.platform == 'darwin':
            self._action_no_icon = QAction(*args, **kwargs)
            self._action_no_icon.setIcon(QIcon())
            self._action_no_icon.triggered.connect(self.triggered)
            self._action_no_icon.toggled.connect(self.toggled)
            self._action_no_icon.changed.connect(self.changed)
            self._action_no_icon.hovered.connect(self.hovered)
        else:
            self._action_no_icon = self

    def __getattribute__(self, name):
        """Intercept method calls and apply to both actions, except signals."""
        attr = super(SpyderAction, self).__getattribute__(name)

        if hasattr(attr, '__call__') and name not in ['triggered', 'toggled',
                                                      'changed', 'hovered']:
            def newfunc(*args, **kwargs):
                result = attr(*args, **kwargs)
                if name not in ['setIcon']:
                    action_no_icon = self.__dict__['_action_no_icon']
                    attr_no_icon = super(QAction,
                                         action_no_icon).__getattribute__(name)
                    attr_no_icon(*args, **kwargs)
                return result
            return newfunc
        else:
            return attr

    @property
    def no_icon_action(self):
        """Return the action without an Icon."""
        return self._action_no_icon
开发者ID:silentquasar,项目名称:spyder,代码行数:42,代码来源:qthelpers.py

示例5: create_action

# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setIcon [as 别名]
def create_action(parent, text, on_triggered=None, shortcut=None,
                  shortcut_context=None, icon_name=None):
    """Create a QAction based on the give properties

    :param parent: The parent object
    :param text: Text string to display
    :param on_triggered: An optional slot to call on the triggered signal
    :param shortcut: An optional shortcut
    :param shortcut_context: An optional context for the supplied shortcut.
    Only applies if a shortcut has been given
    :param icon_name: The name of the qt awesome uri for an icon.
    :return: A new QAction object
    """
    action = QAction(text, parent)
    if on_triggered is not None:
        action.triggered.connect(on_triggered)
    if shortcut is not None:
        action.setShortcut(shortcut)
        if shortcut_context is not None:
            action.setShortcutContext(shortcut_context)
    if icon_name is not None:
        action.setIcon(get_icon(icon_name))

    return action
开发者ID:samueljackson92,项目名称:mantid,代码行数:26,代码来源:__init__.py

示例6: ObjectExplorer

# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setIcon [as 别名]
class ObjectExplorer(QTreeView):
    nodevalue_changed = pyqtSignal(AbstractJsonItem)
    nodeproperty_changed = pyqtSignal(AbstractJsonItem)

    def __init__(self, rootnode: JsonNode, parent):
        super().__init__(parent)
        self.mainwindow = parent
        self.setModel(JsonDataModel(rootnode, self.mainwindow))
        self.model().dataChanged.connect(self.data_changed)
        self.setItemDelegate(MyItemDelegate())
        self.setDragDropMode(QTreeView.DragDrop)
        self.setDragEnabled(True)
        self.setAcceptDrops(True)
        self.setDropIndicatorShown(True)
        self.doubleClicked.connect(self.double_clicked)

        # context menu
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.show_contextmenu)

        # actions
        # properties action
        self.propertiesAction = QAction(self.tr("properties"), self)
        self.propertiesAction.setIcon(QIcon(pixmap("document_properties.png")))
        self.propertiesAction.triggered.connect(self.show_properties)

        # edit action
        self.editAction = QAction(self.tr("edit value"), self)
        self.editAction.setShortcut("F2")
        self.editAction.setIcon(QIcon(pixmap("edit.png")))
        self.editAction.triggered.connect(self.edit_value)

        # edit key action
        self.editkeyAction = QAction(self.tr("edit key"), self)
        self.editkeyAction.setIcon(QIcon(pixmap("kgpg_key1_kgpg.png")))
        self.editkeyAction.triggered.connect(self.edit_key)

        # insert item action
        self.insertitemAction = QAction(self.tr("insert item"), self)
        self.insertitemAction.setIcon(QIcon(pixmap("list_add.png")))
        self.insertitemAction.triggered.connect(self.insert_item)

        # insert node action
        self.insertnodeAction = QAction(self.tr("insert node"), self)
        self.insertnodeAction.setIcon(QIcon(pixmap("list_add.png")))
        self.insertnodeAction.triggered.connect(self.insert_node)

        # remove item action
        self.removeitemAction = QAction(self.tr("remove"), self)
        self.removeitemAction.setIcon(QIcon(pixmap("list_remove")))
        self.removeitemAction.triggered.connect(self.remove_item)

    def data_changed(self, topleft, bottomright, *args):
        node = topleft.internalPointer()
        if node is not None and isinstance(node, JsonItem):
            self.nodevalue_changed.emit(node)

    def double_clicked(self, *args, **kwargs):
        index = self.currentIndex()

        if not index.isValid():
            return

        column = self.model().columns[index.column()]
        if column.name == "value":
            self.edit_value()
        else:
            self.show_properties()

    def edit_key(self):
        index = self.currentIndex()
        if index.isValid():
            node = index.internalPointer()
            key, b = QInputDialog.getText(
                self, "Edit Json item", "Insert new key for item:",
                text=node.key
            )

            if not b:
                return

            node.key = key

            try:  # PyQt5
                self.model().dataChanged.emit(index, index, [Qt.DisplayRole])
            except TypeError:  # PyQt4, PySide
                self.model().dataChanged.emit(index, index)

    def edit_value(self):
        index = self.currentIndex()
        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():
#.........这里部分代码省略.........
开发者ID:MrLeeh,项目名称:jsonwatchqt,代码行数:103,代码来源:objectexplorer.py

示例7: MainWindow

# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setIcon [as 别名]
class MainWindow(QMainWindow):

    def __init__(self, parent=None):
        super().__init__(parent)
        self.recording_enabled = False
        self.serial = serial.Serial()
        self.rootnode = JsonNode('')
        self._connected = False
        self._dirty = False
        self._filename = None

        # settings
        self.settings = QSettingsManager()
        set_default_settings(self.settings)

        # Controller Settings
        self.settingsDialog = None

        # object explorer
        self.objectexplorer = ObjectExplorer(self.rootnode, self)
        self.objectexplorer.nodevalue_changed.connect(self.send_serialdata)
        self.objectexplorer.nodeproperty_changed.connect(self.set_dirty)
        self.objectexplorerDockWidget = QDockWidget(self.tr("object explorer"),
                                                    self)
        self.objectexplorerDockWidget.setObjectName(
            "objectexplorer_dockwidget")
        self.objectexplorerDockWidget.setWidget(self.objectexplorer)

        # plot widget
        self.plot = PlotWidget(self.rootnode, self.settings, self)

        # plot settings
        self.plotsettings = PlotSettingsWidget(self.settings, self.plot, self)
        self.plotsettingsDockWidget = QDockWidget(self.tr("plot settings"),
                                                  self)
        self.plotsettingsDockWidget.setObjectName("plotsettings_dockwidget")
        self.plotsettingsDockWidget.setWidget(self.plotsettings)

        # log widget
        self.loggingWidget = LoggingWidget(self)
        self.loggingDockWidget = QDockWidget(self.tr("logger"), self)
        self.loggingDockWidget.setObjectName("logging_dockwidget")
        self.loggingDockWidget.setWidget(self.loggingWidget)

        # record widget
        self.recordWidget = RecordWidget(self.rootnode, self)
        self.recordDockWidget = QDockWidget(self.tr("data recording"), self)
        self.recordDockWidget.setObjectName("record_dockwidget")
        self.recordDockWidget.setWidget(self.recordWidget)

        # actions and menus
        self._init_actions()
        self._init_menus()

        # statusbar
        statusbar = self.statusBar()
        statusbar.setVisible(True)
        self.connectionstateLabel = QLabel(self.tr("Not connected"))
        statusbar.addPermanentWidget(self.connectionstateLabel)
        statusbar.showMessage(self.tr("Ready"))

        # layout
        self.setCentralWidget(self.plot)
        self.addDockWidget(Qt.LeftDockWidgetArea,
                           self.objectexplorerDockWidget)
        self.addDockWidget(Qt.LeftDockWidgetArea, self.plotsettingsDockWidget)
        self.addDockWidget(Qt.BottomDockWidgetArea, self.loggingDockWidget)
        self.addDockWidget(Qt.BottomDockWidgetArea, self.recordDockWidget)

        self.load_settings()

    def _init_actions(self):
        # Serial Dialog
        self.serialdlgAction = QAction(self.tr("Serial Settings..."), self)
        self.serialdlgAction.setShortcut("F6")
        self.serialdlgAction.setIcon(QIcon(pixmap("configure.png")))
        self.serialdlgAction.triggered.connect(self.show_serialdlg)

        # Connect
        self.connectAction = QAction(self.tr("Connect"), self)
        self.connectAction.setShortcut("F5")
        self.connectAction.setIcon(QIcon(pixmap("network-connect-3.png")))
        self.connectAction.triggered.connect(self.toggle_connect)

        # Quit
        self.quitAction = QAction(self.tr("Quit"), self)
        self.quitAction.setShortcut("Alt+F4")
        self.quitAction.setIcon(QIcon(pixmap("window-close-3.png")))
        self.quitAction.triggered.connect(self.close)

        # Save Config 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")))
#.........这里部分代码省略.........
开发者ID:MrLeeh,项目名称:jsonwatchqt,代码行数:103,代码来源:mainwindow.py


注:本文中的qtpy.QtWidgets.QAction.setIcon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。