3

I am finding trouble with attaching the same icon in the task bar manager for pyqt5 application as I did for the icon of pyqt5 application. I have attached below code for icon display in pyqt5, just need a bit help that how to code for displaying of same icon of Application to the task bar. enter image description here

enter image description here

import sys
from SplashScreen import *
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QColor, qGray, QImage, QPainter, QPalette,QIcon
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtWidgets import QApplication, QWidget
if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setWindowIcon(QIcon('./cricket.png'))
    w = QWidget()
    w.resize(300,300)
    w.setWindowTitle('Quick Cricket')
    w.show()
    sys.exit(app.exec_())

Thanks in advance

Abdul Rehman
  • 167
  • 2
  • 14
  • Please post code as text, not as image. Then, ensure that you provide a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – musicamante May 19 '21 at 08:28
  • `import sys from SplashScreen import * from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtGui import QColor, qGray, QImage, QPainter, QPalette,QIcon from PyQt5.QtCore import Qt, QUrl from PyQt5.QtWidgets import QApplication, QWidget if __name__ == "__main__": app = QApplication(sys.argv) app.setWindowIcon(QIcon('./cricket.png')) w = QWidget() w.resize(300,300) w.setWindowTitle('Quick Cricket') w.show() sys.exit(app.exec_())` – Abdul Rehman May 19 '21 at 08:57
  • Here is the sample code – Abdul Rehman May 19 '21 at 08:58
  • don't use comments, as they don't support formatting and they make difficult to read code. Edit the question instead, and follow the guidelines about [formatting code](https://meta.stackoverflow.com/a/251362). – musicamante May 19 '21 at 10:17
  • @musicamante still waiting for answer – Abdul Rehman May 21 '21 at 04:31
  • I just pointed out problems in your questions, it doesn't mean I know tje answer. Please avoid unnecessary usage of comments, and *be patient*, this is not a forum nor a chat, and absolutely not a race: sometimes answers are given *years` after a question is asked. – musicamante May 21 '21 at 09:01

2 Answers2

5

Guess What I found the Answer.

I used three lines of Code at the start of my application and then run the code and windows show me same icon as it was my logo.

import ctypes
myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)

What these lines do? So in short these lines will tell the window that this is my own registered application, so I will decide the icon of it.

I will give all credit to @DamonJW Stack Overflow Developer. Thanks @DamonJW. Here is the link of solution

< https://stackoverflow.com/questions/1551605/how-to-set-applications-taskbar-icon-in-windows-7/1552105#1552105>

Abdul Rehman
  • 167
  • 2
  • 14
0

enter image description here

The solution is in this line

import ctypes
myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
Azhar Khan
  • 3,829
  • 11
  • 26
  • 32