pythonguis / feedback

Corrections & suggestions for Python GUIs tutorials on pythonguis.com
1 stars 0 forks source link

linux_icons.py #24

Open flideros opened 5 days ago

flideros commented 5 days ago

I could not get the original code to work so I want to suggest the following code with three methods for getting the icons to work properly.

from PyQt6.QtWidgets import QApplication, QPushButton, QStyle from PyQt6.QtGui import QIcon from PyQt6.QtCore import QSize

import sys

app = QApplication(sys.argv) button = QPushButton("Hello")

Method 1 -- Direct Pointer

icon = QIcon("/usr/share/icons/PiXflat/16x16/apps/web-browser.png")

Method 2 -- Standard Icons

style = app.style()

icon = style.standardIcon(QStyle.StandardPixmap.SP_FileDialogNewFolder)

Method 3 -- Explicit Theme

QIcon.setThemeName("Adwaita") icon = QIcon.fromTheme("document-new")

button.setIcon(icon) button.setIconSize(QSize(24,24)) button.show()

iconNull = icon.isNull() print(iconNull)

app.exec()

lpozo commented 1 day ago

@flideros Hey! Could you please provide the link to the article where you got the original code?

flideros commented 2 hours ago

https://www.pythonguis.com/d/pyqt6-source.zip