5

I want to create a windows desktop widget. I will create a custom UI for the widget in Qt Designer and add functionality using Python. But, I do not want the application to have an icon on the taskbar at all. How should I modify my code and make my application (and its instances or other similar applications) to have no task bar footprint?

How can I hide the taskbar icon on windows? Here is an example code:

import sys
from PyQt4 import QtGui
from PyQt4.uic import loadUiType

Ui_MainWindow, QMainWindow = loadUiType('try.ui')

class Main(QMainWindow, Ui_MainWindow):
    def __init__(self, ):
        super(Main, self).__init__()
        self.setupUi(self)

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    main = Main()
    main.show()
    sys.exit(app.exec_())

and this is its ui, "try.ui":

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Form</class>
 <widget class="QWidget" name="Form">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>211</width>
    <height>157</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
  <widget class="QPushButton" name="pushButton">
   <property name="geometry">
    <rect>
     <x>60</x>
     <y>60</y>
     <width>75</width>
     <height>23</height>
    </rect>
   </property>
   <property name="text">
    <string>PushButton</string>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

Edit: Here is how default icon looks like on the taskbar. I just do not want it there, as expected from a widget.

smoothy
  • 79
  • 8
  • How does the icon look? What does it say? Is it the default pythonwindows icon? – oxalorg Jun 19 '16 at 18:55
  • @MiteshNinja: It's just a regular default icon showing on the taskbar, but I do not want it there and could not find a way to hide it. – smoothy Jun 19 '16 at 20:16

2 Answers2

4

Try this:

from PyQt4 import QtCore
...
class Main(QMainWindow, Ui_MainWindow):
    def __init__(self, ):
        super(Main, self).__init__()
        self.setWindowFlags(QtCore.Qt.Tool)       #This
Stevo Mitric
  • 1,570
  • 18
  • 19
  • Thank you Stevo, this is it. I want to note something funny about this method though: When I run a second instance, for the first time, the original instance disappears, if I run couple of more instances and click on desktop, they all disappear from screen. After that however on secondary trials, all works fine. I do not know what causes this at this point but your answer solves my problem and I accepted it. Do you also know how to make the app frame-less at the same time? This would be more like a widget. – smoothy Jun 20 '16 at 19:28
  • I think that's a whole new question, but quick answer would be to use the same method: `setWindowFlags(QtCore.Qt.FramelessWindowHint)` – Stevo Mitric Jun 20 '16 at 19:43
1

I think this may be the problem:

In Windows 7, the taskbar is not for "Application Windows" per se, it's for "Application User Models". For example, if you have several different instances of your application running, and each instance has its own icon, then they will all be grouped under a single taskbar icon. Windows uses various heuristics to decide whether different instances should be grouped or not, and in this case it decided that everything hosted by Pythonw.exe should be grouped under the icon for Pythonw.exe.

The correct solution is for Pythonw.exe to tell Windows that it is merely hosting other applications. Perhaps a future release of Python will do this. Alternatively, you can add a registry key to tell Windows that Pythonw.exe is just a host rather than an application in its own right. See MSDN documentation for AppUserModelIDs.

Alternatively, you can use a Windows call from Python, to explicitly tell Windows what the correct AppUserModelID is for this process:

import ctypes myappid = 'mycompany.myproduct.subproduct.version' #
arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
Community
  • 1
  • 1
oxalorg
  • 2,768
  • 1
  • 16
  • 27
  • This is not what I am looking for. I do not want the application to have an icon on the taskbar at all. How should I modify my code and make my application (and its instances or other similar applications) to have no task bar footprint? This is more like what I need. Thank you for the reply. – smoothy Jun 20 '16 at 17:09