Hide window from taskbar

I'm trying to minimize a window to the tray, but it seems it refuses to hide from the taskbar. I've spent a little time and distilled the problem code down to this. It's not mcuh so I'm wondering if I need something else to hide my app to tray in Windows 7.

import sys, os
from PyQt4 import uic 
from PyQt4.QtGui import QMainWindow, QApplication

class MyClass(QMainWindow):
    def __init__(self, parent = None):
        QMainWindow.__init__(self, parent)
        self.ui = uic.loadUi(os.path.join("gui", "timeTrackerClientGUI.ui"), self)
    def hideEvent(self, event):
        self.hide()
    def showEvent(self, event):
        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    wnd = MyClass()
    wnd.show()
    app.exec_()

It seems the application icon does hide but then another one pops up, If I click the taskbar icon multiple times I can get these two icons flickering, looks kind of like this for a splitsecond before the first one hides:

Answers


calling show/hide in showEvent()/hideEvent() doesn't make sense - those events are the result of show()/hide() calls (and the like), not the trigger. If you want to toggle the window visiblity by clicking the tray icon, try setVisible(!isVisible()) on the widget, if you want to hide the window when the user clicks the window close button try reimplementing closeEvent():

MyMainWindow::closeEvent( QCloseEvent* e ) {
    hide();
    e->accept();
}

In Python, that is

def closeEvent(self, event):
    self.hide()
    event.accept()

It took a quite ugly hack to get it working but here's the final code if anybody is interested, ph is my platform-specific module, you can use platform.name or similar function instead:

def hideEvent(self, event):
    self.hide()
    if ph.is_windows():
        self.hidden = True
        self.setWindowFlags(Qt.ToolTip)
def showEvent(self, event):
    if ph.is_windows() and self.hidden:
        self.setWindowFlags(Qt.Window)
        self.hidden = False
    self.show()

Need Your Help

Qt Show/Hide widget animation

qt animation qwidget

I'm trying to implement a show/hide widget animation. The widget is a QDockWidget and therefore is inside the QMainWindowLayout.

Embed PDF in IE10

internet-explorer pdf embed pdf-viewer

I need to embed a PDF in an HTML document that can be viewed in IE8/9/10, firefox, and chrome on a .Net application. I need to stay away from 3rd party libraries because we need to meet a release ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.