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 .
Qt ships with a small set of standard icons you can use in any of your applications for common actions. The icons are all accessible through the current active application style -- available as a series of flags, which can be passed to .
The key difference in the two versions — in fact the entire reason PySide2 exists — is licensing. PyQt5 is available under a GPL or commercial license, and PySide2 under a LGPL license.
PySide is LGPL while PyQt is GPL. This could make a difference if you don't wish to make your project opensource. Although PyQt always has the propriety version available for a fairly reasonable price. I tend to find the PySide documentation more intuitive.
Advantages of PySide PySide represents the official set of Python bindings backed up by the Qt Company. PySide comes with a license under the LGPL, meaning it is simpler to incorporate into commercial projects when compared with PyQt. It allows the programmer to use QtQuick or QML to establish the user interface.
What you need is Pyside QIcon.fromTheme function. Basicaly it creates QIcon object with needed icon from current system theme.
Usage:
undoicon = QIcon.fromTheme("edit-undo")
"edit undo" - name of the icon "type"/"function" can be found here
This works on X11 systems, for MacOSX and Windows check QIcon documentation QIcon.fromTheme
Edit Inserting this from the website, since last time it was a broken link.
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()
There is another way to access some of the standard builtin icons in PyQt/PySide using the standard pixmap in the default style. For example, the following creates an icon for opening a file:
self.style().standardIcon(QtGui.QStyle.SP_DialogOpenButton)
For the full list of standard pixmaps, see:
http://srinikom.github.io/pyside-docs/PySide/QtGui/QStyle.html#PySide.QtGui.PySide.QtGui.QStyle.StandardPixmap
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With