[PyQt] QIcon not displaying - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [PyQt] QIcon not displaying (/thread-3329.html) |
QIcon not displaying - metulburr - May-16-2017 Im running through PyQt5 tuts and came across a couple of tutorials that use QIcon. I cant get anything given to QIcon to work at all whether its through QAction or setting the window icon via... self.setWindowIcon(QtGui.QIcon('py.png'))I tried the following based on google search results:
full code: import sys from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication from PyQt5.QtGui import QIcon from PyQt5.QtCore import QFile class Example(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): print(QFile.exists('py.png')) exitAction = QAction(QIcon('/home/metulburr/py.png'), '&Exit', self) exitAction.setShortcut('Ctrl+Q') exitAction.setStatusTip('Exit application') exitAction.triggered.connect(qApp.quit) self.statusBar() menubar = self.menuBar() fileMenu = menubar.addMenu('&File') fileMenu.addAction(exitAction) self.setGeometry(300, 300, 300, 200) self.setWindowTitle('Menubar') self.show() if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())Anything given to QIcon is as if the line didnt exist at all. Ubuntu 16.04 My system was acting wacky so i did a complete fresh install again. Maybe i am missing a dependency or something? RE: QIcon not displaying - Fred Barclay - May-18-2017 Not to rub salt in the wound, but your code works perfectly on my system (Debian Sid). I'm running the script from my Documents folder and the image in in ~/Pictures. The only change I made was providing a full path to print(QFile.exists('py.png')): print(QFile.exists('/home/fred/Pictures/Adam.png'))I wonder what would happen if you used os.path.asbpath? Something like from os.path import abspath img_path = abspath('/home/metulburr/py.png') exitAction = QAction(QIcon(img_path), '&Exit', self)It ought not change anything but you never know. RE: QIcon not displaying - metulburr - May-18-2017 Quote:I wonder what would happen if you used os.path.asbpath?Notta. But now i am wondering if it is a desktop issue. What desktop are you using? RE: QIcon not displaying - snippsat - May-18-2017 Works fine for my with .png in same folder as scripts in both Win-10 and Mint 18.1. metulburr Wrote:My system was acting wacky so i did a complete fresh install again. Maybe i am missing a dependency or something?Virtual environment I run PyQt5 in virtual environment in both Win-10 and Mint,not gone install it in OS python. RE: QIcon not displaying - metulburr - May-18-2017 Its got to be an issue with Ubuntu's Unity then because as soon as i installed another desktop it started working now problem. Another tally for it heading out. RE: QIcon not displaying - Fred Barclay - May-18-2017 (May-18-2017, 11:56 AM)metulburr Wrote: Notta. But now i am wondering if it is a desktop issue. What desktop are you using? MATE 1.16.1 RE: QIcon not displaying - metulburr - May-18-2017 im prolly going to move to a tile window manager soon. RE: QIcon not displaying - snippsat - May-18-2017 (May-18-2017, 04:35 PM)metulburr Wrote: Its got to be an issue with Ubuntu's UnityUnity is dead,so best to switch. |