Open flideros opened 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")
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()
@flideros Hey! Could you please provide the link to the article where you got the original code?
https://www.pythonguis.com/d/pyqt6-source.zip
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()