Why isn't the PyQt5 QPushButton or QAction showing the desired image in Qtoolbar
Question:
I have the following code to show an image of 16×16 or 16×12 in jpg and png format using QPushButton:
navbar=QToolBar()
btn=QPushButton()
btn.setIcon(QIcon(QPixmap("back.jpg"))) #or .png
btn.clicked.connect(self.btn_pressed)
navbar.addWidget(btn)
I also tried just using QAction like so:
navbar=QToolBar()
action=QAction(QIcon(QPixmap("back.jpg")),"back",self)
action.triggered.connect(self.btn_pressed)
navbar.addAction(action)
They always either show the text or the actual button but empty with no text or rendered image and I can’t see where everything fails.
Answers:
As @furas mentioned Current Working Directory
depends on which command line path the file is started and it was constantly changing so the dependency on my relative path was causing the issue.
I have the following code to show an image of 16×16 or 16×12 in jpg and png format using QPushButton:
navbar=QToolBar()
btn=QPushButton()
btn.setIcon(QIcon(QPixmap("back.jpg"))) #or .png
btn.clicked.connect(self.btn_pressed)
navbar.addWidget(btn)
I also tried just using QAction like so:
navbar=QToolBar()
action=QAction(QIcon(QPixmap("back.jpg")),"back",self)
action.triggered.connect(self.btn_pressed)
navbar.addAction(action)
They always either show the text or the actual button but empty with no text or rendered image and I can’t see where everything fails.
As @furas mentioned Current Working Directory
depends on which command line path the file is started and it was constantly changing so the dependency on my relative path was causing the issue.