[PyQt] Application not hiding from taskbar

Hans-Peter Jansen hpj at urpla.net
Mon Dec 6 13:33:52 GMT 2010


On Monday 06 December 2010, 13:13:44 Mikael Modin wrote:
> I figured out how to solve my little conundrum. My solution is so
> ugly I'm ashamed but I can't figure out why self.hide() doesn't hide
> my window in the first place. Here's the final code:
>
>     def hideEvent(self, event):
>         self.hide()
	  super(MyWnd, self).hideEvent(event)
>         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()

Hehe, glad, I could help (on IRC..). Try calling the parent here instead 
of hide(), this should have the same result. I wonder, why your code 
works at all this way. You're lucky, that Qt is smart enough to not 
generate an endless loop here (I guess, that Qt checks, if the widget 
is hidden already, and avoids generating another event then).

Mikael, if you think, that this is a worse hack, you're really lucky. 

Doing a PyQt3 systray app using extended window flags like skipping 
taskbar and pager, sticky and stays on top state, global shortcuts, 
etc. was _really_ adventurous: that needed using about 20 functions of 
libX11 together with unioned binary structures handled via ctypes! This 
is completely unportable, depending on certain window manager behavior, 
of course..

Now that IS dirty, but even that is not in a company with say: fixing 
library symbols using sed in certain "professional" products like 
Google Earth:

http://www.google.com/support/forum/p/earth/thread?tid=3e5b58f141268929&hl=en

Pete

> Kind regards,
> Mikael
>
> On 4 December 2010 00:40, Mikael Modin <micke.modin at gmail.com> wrote:
> > Hi,
> >
> > I'm trying to implement minimize-to-tray but my application refuses
> > to hide from taskbar. I've distilled the problematic code down to
> > this little snippet, attached .ui-file.
> >
> > 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()
> >
> > if __name__ == '__main__':
> >    app = QApplication(sys.argv)
> >    wnd = MyClass()
> >    wnd.show()
> >    app.exec_()
> >
> > According to
> > http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwidget.
> >html#hideEvent I get a hideEvent when the user minimizes the window
> > and that part works, but self.hide() doesn't hide my window from
> > the taskbar. It's working fine in Linux, but in Windows 7 it
> > refuses to hide. It looks like one icon hides but then another one
> > pops up beside it, if I click quick enough you get this flickering
> > effect I managed to catch in a screenshot,
> > http://dl.dropbox.com/u/3184097/problem2.png
> > I'm stumped, thought this would be simple to do.
> >
> > Kind regards
> > Mikael Modin
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt




More information about the PyQt mailing list