0

I am trying to show the icon in the window bar and this is not simply working. I tried several solutions but still it doesn't work. Any solution for this code?

import os
from PyQt5.QtCore import *
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *


class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.browser = QWebEngineView()
        self.browser.setUrl(QUrl('http://gmail.com'))
        self.setCentralWidget(self.browser)
        self.showMaximized()

        self.setWindowTitle('G')
        self.setWindowIcon(QIcon(os.path.join('cil.png')))
        self.show()


app = QApplication(sys.argv)

window = MainWindow()
app.exec_()


  • 1
    `os.path.join` with a single argument is completely useless, since there's nothing to join. The file is probably in a directory different from the *working* directory (the one from which the python interpreter or script is called). If the image is in the same directory as the script, build the path using `join` with `os.path.dirname(__file__)`. – musicamante Oct 09 '22 at 15:00
  • still it doesn't work. –  Oct 10 '22 at 15:08
  • Then, ensure that the path you created was correct (try, for instance, `os.path.isfile()` or `os.path.exists()`), and that the file is *actually* in a correct format (the extension is pointless, for all we know that could even be a text file that has just been renamed). – musicamante Oct 10 '22 at 16:28

1 Answers1

0

Try putting the icon like this

icon = QIcon()
icon.addPixmap(QtGui.QPixmap())  #add full path or respective path to the icon image inside QtGui.QPixmap()
self.setWindowIcon(icon)