I'm probably missing something obvious, but the following code doesn't seem to display the app_icon in the window title bar. The app_icon.png is a 24x24px file in the same folder as main.py and ui_mainwindow.py. The Qt docs seems to suggest PySide6.QtGui.QIcon(fileName) is a valid approach, but maybe I'm misinterpreting it. Aside from this issue, the rest of the app works fine.
from PySide6.QtGui import QIcon, QScreen
from PySide6.QtWidgets import QApplication, QFileDialog, QMainWindow
from ui_mainwindow import Ui_MainWindow
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
# Change a few things
screenSize = QScreen.availableGeometry(QApplication.primaryScreen())
winXpos = ((screenSize.width() - self.width())/2)
winYpos = ((screenSize.height() - self.height())/2)
self.move(winXpos, winYpos)
self.setWindowTitle('App - Main Window')
self.setWindowIcon(QIcon('app_icon.png'))
...rest of the code...
Changing it to the following, results in an error
self.setWindowIcon(QIcon.addFile('app_icon.png'))
TypeError: descriptor 'addFile' for 'PySide6.QtGui.QIcon' objects doesn't apply to a 'str' object
This is on linux, using Python3.8.10 and PySide6. The form was put together with Qt Creator and the .ui converted to .py using pyside6-uic. Any ideas where I'm going wrong?
EDIT: screenshot of missing icon, post changes suggested in the comments