本文介绍了PyQt / PySide中是否有默认图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在阅读关于PySide的教程,我在想,我是否需要为每件事找到自己的图标,或者是否有某种方法可以使用一些内置图标。这样,如果我想让我的小gui在另一个桌面环境中运行,我就不需要找到一整套新的图标。I'm reading a tutorial on PySide and I was thinking , do I need to find my own icons for every thing or is there some way to use some built in icons . That way I wouldn't need to find an entire new set of icons if I want my little gui to run on another desktop environment .推荐答案您需要的是Pyside QIcon.fromTheme功能。 Basicaly它使用当前系统主题中的所需图标创建QIcon对象。What you need is Pyside QIcon.fromTheme function.Basicaly it creates QIcon object with needed icon from current system theme.用法: undoicon = QIcon.fromTheme(edit-undo)edit undo - 图标名称type /function可以在这里找到"edit undo" - name of the icon "type"/"function" can be found here这适用于X11系统,适用于MacOSX和Windows检查QIcon文档 QIcon.fromThemeThis works on X11 systems, for MacOSX and Windows check QIcon documentationQIcon.fromTheme 修改从网站上插入此内容,因为上次链接已损坏。Edit Inserting this from the website, since last time it was a broken link. 参数: 名称 - 联合国icode 后备 - PySide.QtGui.QIcon name – unicode fallback – PySide.QtGui.QIcon 返回输入: PySide.QtGui.QIcon返回 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.可以在此处获取最新版本的freedesktop图标规范和命名规范:The latest version of the freedesktop icon specification and naming specification can be obtained here: http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html http://standards.freedesktop.org/icon-naming- spec / icon-naming-spec-latest.html http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html从当前图标主题中获取图标: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"))默认情况下,只有X11会支持主题图标。要在Mac和Windows上使用主题图标,您必须在一个 PySide.QtGui.QIcon.themeSearchPaths()并设置相应的 PySide.QtGui.QIcon.themeName()。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() . 参见 PySide.QtGui .QIcon.themeName() PySide.QtGui.QIcon.setThemeName() PySide.QtGui.QIcon.themeSearchPaths() PySide.QtGui.QIcon.themeName() PySide.QtGui.QIcon.setThemeName() PySide.QtGui.QIcon.themeSearchPaths() 这篇关于PyQt / PySide中是否有默认图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-14 19:50