gpt4 book ai didi

python - PyQt/PySide 中是否有默认图标?

转载 作者:IT老高 更新时间:2023-10-28 22:24:28 26 4
gpt4 key购买 nike

我正在阅读有关 PySide 的教程,我在想,我是否需要为每件事找到自己的图标,或者有什么方法可以使用一些内置图标。这样,如果我想让我的小 gui 在另一个桌面环境上运行,我就不需要找到一套全新的图标。

最佳答案

你需要的是 Pyside QIcon.fromTheme 函数。基本上,它使用当前系统主题中所需的图标创建 QIcon 对象。

用法:

undoicon = QIcon.fromTheme("edit-undo")

“编辑撤消” - 图标“类型”/“功能”的名称可以找到here

这适用于 X11 系统,对于 MacOSX 和 Windows,请查看 QIcon 文档 QIcon.fromTheme

编辑从网站插入这个,因为上次它是一个损坏的链接。

static PySide.QtGui.QIcon.fromTheme(name[, fallback=QIcon()])

Parameters:

Return type:

PySide.QtGui.QIcon

Returns the PySide.QtGui.QIcon corresponding to name in the current icon theme. If no such icon is found in the current theme fallback is returned instead.

The latest version of the freedesktop icon specification and naming specification can be obtained here:

To fetch an icon from the current icon theme:

undoicon = QIcon.fromTheme("edit-undo")

Or if you want to provide a guaranteed fallback for platforms that do not support theme icons, you can use the second argument:

undoicon = QIcon.fromTheme("edit-undo", QIcon(":/undo.png"))

Note

By default, only X11 will support themed icons. In order to use themed icons on Mac and Windows, you will have to bundle a compliant theme in one of your PySide.QtGui.QIcon.themeSearchPaths() and set the appropriate PySide.QtGui.QIcon.themeName() .

See also

关于python - PyQt/PySide 中是否有默认图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11643221/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com