static PySide.QtGui.QIcon.fromTheme(name[, fallback=QIcon()])
Parameters:
name – unicode
fallback – PySide.QtGui.QIcon
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:
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"))
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
PySide.QtGui.QIcon.themeName()
PySide.QtGui.QIcon.setThemeName()
PySide.QtGui.QIcon.themeSearchPaths()
< /块引用>
哦!我很兴奋终于找到了一个标准qt图标的列表,但是第二个链接现在似乎被破坏了。有什么更新吗?
@Michaelscheper如果你没有收到我更新答案的通知,答案已经用新链接和相关文本更新。
还有另一种方法可以使用默认样式中的标准pixmap访问pyqt/pyside中的一些标准内置图标。例如,下面创建一个用于打开文件的图标:
self.style().standardIcon(QtGui.QStyle.SP_DialogOpenButton)
有关标准像素地图的完整列表,请参见:
http://srinikom.github.io/pyside-docs/pyside/qtgui/qstyle.html pyside.qtgui.pyside.qtgui.qstyle.standardpixmap
self是指QtWidgets.QApplication(qt5)或QtGui.QApplication(qt4),如果你想在self不是上述的情况下使用。
很遗憾,这些SP_图标如此有限。我希望他们能在名单上多加一些。
我不认为这是特定于任何绑定的,您可以查看qt常规文档
看看这里和这里
相关问题
我一直找不到标准图标的图像,所以以后参考:http://nukesaq88.hatenablog.com/entry/2013/04/12/005525
我使用的代码(pyqt4,pyside可能类似):
# In method of QMainWindow subclass
stdicon = self.style().standardIcon
style = QtGui.QStyle
reload_foo = QtGui.QAction(stdicon(style.SP_BrowserReload), '&Reload', self)
如果(显然是自动生成的)qt文档在standardicons枚举表中有图片,那就太好了…
另一个使用标准图标的pyqt5示例(eqzx的答案对我不起作用):
from PyQt5.QtWidgets import QApplication, QStyle
from PyQt5.QtGui import QIcon
desktop_icon = QIcon(QApplication.style().standardIcon(QStyle.SP_DesktopIcon)
在PyQt5中,有一个简单的例子,创建一个带有播放图标的按钮:
play_button = QtGui.QPushButton('Play video')
play_button.setIcon(QtGui.QApplication.style().standardIcon(QtGui.QStyle.SP_MediaPlay))
qt5文档提供了可能的sp("标准pixmap")图标列表。见enum QStyle::StandardPixmap这里:http://doc.qt.io/qt-5/qstyle.html
你说真的吗?那是Pyqt4而不是Pyqt5。
在pyqt中,窗口图标默认为qt徽标。我认为您必须在GUI中找到自己的图标。