I have been learning python for 4 months. Started developing a simple app with qtcreator and pyside 6. Main window initialized and launched but got stuck trying to set icon to main window. Tried many various options - nothing works. I work on Windows10, all project files are UTF-8 encoded. PNG images are not displayed either directly or through a .qrc file. The current version of the code is the following:
import sys
from PySide6.QtGui import QIcon, QPixmap, Qt
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget
import resources
from ui_mainwindow import UiKonDiphone
class MainWindow(QMainWindow, QWidget):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.ui = UiKonDiphone()
self.ui.setupUi(self)
icon = QIcon()
icon.addPixmap(QPixmap(u":/icon/icons/main_icon_24.png"))
self.setWindowIcon(icon)
return
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
The .qrc file looks like this:
<RCC>
<qresource prefix="/icons">
<file>icon/main_icon_24.png</file>
<file>icon/pause_icon_98.png</file>
<file>icon/record_icon_98.png</file>
</qresource>
</RCC>
Initially wrote with "self.setWindowIcon(QIcon())", but that done nothing. Tried to add icon directly from qt creator. also:
class UiKonDiphone(object):
KonDiphone.setToolButtonStyle(Qt.ToolButtonFollowStyle)
icon = QIcon()
icon.addFile(u":/icons/icon/main_icon_24.png", QSize(), QIcon.Normal, QIcon.Off)
KonDiphone.setProperty("Main_Icon", icon)