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 .
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
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:
For the full list of standard pixmaps, see:
http://srinikom.github.io/pyside-docs/PySide/QtGui/QStyle.html#PySide.QtGui.PySide.QtGui.QStyle.StandardPixmap
I keep having trouble finding images of the standard icons, so for future reference: http://nukesaq88.hatenablog.com/entry/2013/04/12/005525
And the code I'm using (PyQt4, Pyside probably similar):
It would be nice if the (obviously auto-generated) Qt docs had pictures in the standardIcons enum table...
I don't think this is specific to any binding, you can check the qt general documentation
take a look here and here
related question
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.
in PyQt, the window icon is by default the Qt logo. I think you will have to find your own icons for things inside the gui.
In
PyQt5
, here's a simple example of creating a push button with the play icon:The Qt5 documentation provides a list of the possible SP ("Standard Pixmap") icons. See
enum QStyle::StandardPixmap
here: http://doc.qt.io/qt-5/qstyle.html