【问题标题】:How to modify icon of matplotlib navigation如何修改matplotlib导航的图标
【发布时间】:2021-01-31 02:18:17
【问题描述】:

我已经能够使用以下代码删除/禁用不同的 matplotlib 导航工具栏按钮:

canvasplt_matplotlib_toolbar = NavigationToolbar(
    self.canvasplt, self
)

matplotlib_toolbar_with_removed_icons = self.canvasplt.toolbar
unwanted_buttons = ["Back", "Forward", "Customize", "Subplots", "Save"]
for x in matplotlib_toolbar_with_removed_icons.actions():
    if x.text() in unwanted_buttons:
        matplotlib_toolbar_with_removed_icons.removeAction(x)

现在我想更改其余图标的图标设计,例如主页、平移和缩放,使其适合一般的 GUI 设计。

如何使用自己的 .ico 文件修改这些图标?

【问题讨论】:

    标签: python matplotlib pyqt


    【解决方案1】:

    逻辑类似于删除 QAction,因为您必须迭代以获取相应的 QAction 并使用 setIcon 方法替换图标:

    unwanted_buttons = ["Back", "Forward", "Customize", "Subplots", "Save"]
    
    icons_buttons = {
        "Home": QtGui.QIcon("/path/of/home.png"),
        "Pan": QtGui.QIcon("/path/of/pan.png"),
        "Zoom": QtGui.QIcon("/path/of/zoom.png"),
    }
    for action in matplotlib_toolbar_with_removed_icons.actions():
        if action.text() in unwanted_buttons:
            matplotlib_toolbar_with_removed_icons.removeAction(action)
        if action.text() in icons_buttons:
            action.setIcon(icons_buttons.get(action.text(), QtGui.QIcon()))
    

    【讨论】:

      猜你喜欢
      • 2012-09-23
      • 1970-01-01
      • 1970-01-01
      • 2019-11-22
      • 2020-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      相关资源
      最近更新 更多