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


Python QToolButton.setIcon方法代码示例

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


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

示例1: create_toolbutton

# 需要导入模块: from spyderlib.qt.QtGui import QToolButton [as 别名]
# 或者: from spyderlib.qt.QtGui.QToolButton import setIcon [as 别名]
def create_toolbutton(parent, text=None, shortcut=None, icon=None, tip=None,
                      toggled=None, triggered=None,
                      autoraise=True, text_beside_icon=False):
    """Create a QToolButton"""
    button = QToolButton(parent)
    if text is not None:
        button.setText(text)
    if icon is not None:
        if is_text_string(icon):
            icon = get_icon(icon)
        button.setIcon(icon)
    if text is not None or tip is not None:
        button.setToolTip(text if tip is None else tip)
    if text_beside_icon:
        button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
    button.setAutoRaise(autoraise)
    if triggered is not None:
        QObject.connect(button, SIGNAL('clicked()'), triggered)
    if toggled is not None:
        QObject.connect(button, SIGNAL("toggled(bool)"), toggled)
        button.setCheckable(True)
    if shortcut is not None:
        button.setShortcut(shortcut)
    return button
开发者ID:jromang,项目名称:spyderlib,代码行数:26,代码来源:qthelpers.py

示例2: ExplorerWidget

# 需要导入模块: from spyderlib.qt.QtGui import QToolButton [as 别名]
# 或者: from spyderlib.qt.QtGui.QToolButton import setIcon [as 别名]
class ExplorerWidget(QWidget):
    """Explorer widget"""

    sig_option_changed = Signal(str, object)
    sig_open_file = Signal(str)
    sig_new_file = Signal(str)
    redirect_stdio = Signal(bool)
    open_dir = Signal(str)

    def __init__(
        self, parent=None, name_filters=["*.py", "*.pyw"], show_all=False, show_cd_only=None, show_icontext=True
    ):
        QWidget.__init__(self, parent)

        # Widgets
        self.treewidget = ExplorerTreeWidget(self, show_cd_only=show_cd_only)
        button_previous = QToolButton(self)
        button_next = QToolButton(self)
        button_parent = QToolButton(self)
        self.button_menu = QToolButton(self)
        menu = QMenu(self)

        self.action_widgets = [button_previous, button_next, button_parent, self.button_menu]

        # Actions
        icontext_action = create_action(self, _("Show icons and text"), toggled=self.toggle_icontext)
        previous_action = create_action(
            self, text=_("Previous"), icon=ima.icon("ArrowBack"), triggered=self.treewidget.go_to_previous_directory
        )
        next_action = create_action(
            self, text=_("Next"), icon=ima.icon("ArrowForward"), triggered=self.treewidget.go_to_next_directory
        )
        parent_action = create_action(
            self, text=_("Parent"), icon=ima.icon("ArrowUp"), triggered=self.treewidget.go_to_parent_directory
        )
        options_action = create_action(self, text="", tip=_("Options"))

        # Setup widgets
        self.treewidget.setup(name_filters=name_filters, show_all=show_all)
        self.treewidget.chdir(getcwd())
        self.treewidget.common_actions += [None, icontext_action]

        button_previous.setDefaultAction(previous_action)
        previous_action.setEnabled(False)

        button_next.setDefaultAction(next_action)
        next_action.setEnabled(False)

        button_parent.setDefaultAction(parent_action)

        self.button_menu.setIcon(ima.icon("tooloptions"))
        self.button_menu.setPopupMode(QToolButton.InstantPopup)
        self.button_menu.setMenu(menu)
        add_actions(menu, self.treewidget.common_actions)
        options_action.setMenu(menu)

        self.toggle_icontext(show_icontext)
        icontext_action.setChecked(show_icontext)

        for widget in self.action_widgets:
            widget.setAutoRaise(True)
            widget.setIconSize(QSize(16, 16))

        # Layouts
        blayout = QHBoxLayout()
        blayout.addWidget(button_previous)
        blayout.addWidget(button_next)
        blayout.addWidget(button_parent)
        blayout.addStretch()
        blayout.addWidget(self.button_menu)

        layout = QVBoxLayout()
        layout.addLayout(blayout)
        layout.addWidget(self.treewidget)
        self.setLayout(layout)

        # Signals and slots
        self.treewidget.set_previous_enabled.connect(previous_action.setEnabled)
        self.treewidget.set_next_enabled.connect(next_action.setEnabled)

    @Slot(bool)
    def toggle_icontext(self, state):
        """Toggle icon text"""
        self.sig_option_changed.emit("show_icontext", state)
        for widget in self.action_widgets:
            if widget is not self.button_menu:
                if state:
                    widget.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
                else:
                    widget.setToolButtonStyle(Qt.ToolButtonIconOnly)
开发者ID:sonofeft,项目名称:spyder,代码行数:92,代码来源:explorer.py


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