[PyQt] Checking a window's state using '&' is always returning False

Kyle Altendorf sda at fstab.net
Mon Aug 21 21:49:28 BST 2017


On 2017-08-21 16:45, Jayson Kempinger wrote:

> I'm using PyQt 5.8 and trying to detect a window's state by comparing 
> it to known window states using '&', but every comparison returns 
> False.
> 
> For example:
> 
>> if win.windowState() & Qt.WindowNoState:
>> print("normal")
>> elif win.windowState() & Qt.WindowMinimized:
>> print("minimized")
>> elif win.windowState() & Qt.WindowMaximized:
>> print("maximized")
>> else:
>> raise NotImplementedError
> 
> However, the comparison is always false (so I hit the exception), even 
> though _print(int(win.windowState()), int(Qt.WindowNoState))_ shows "0 
> 0".

What is 0 & 0?  0.  Which is False.  :]

> The same syntax for other QFlags seems to work fine:
> 
>> if win.windowType() & Qt.Widget:
>> print("widget")
>> elif win.windowType() & Qt.Window:
>> print("window")
>> else:
>> raise NotImplementedError
> 
> My IDE, PyCharm, believes that the & operator is not defined for the 
> WindowStates class and gives me a warning: `_'WindowStates' does not 
> define '__and__', so the '&' operator cannot be used on its 
> instances_`.  I can't seem to find the 5.8 documentation for this enum, 
> but looking at the PyQt4 documentation 
> (http://pyqt.sourceforge.net/Docs/PyQt4/qt-windowstates.html#__and__) 
> it is defined.
> 
> Is bitwise comparison not available for the WindowStates enum?  Or am I 
> checking it incorrectly?
> 
> Thanks!
> Jayson
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt


More information about the PyQt mailing list