Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test if WindowStaysOnTopHint flag is set in windowFlags?

Is this supposed to return a boolean value?

>>> win.windowFlags() & QtCore.Qt.WindowStaysOnTopHint
<PyQt4.QtCore.WindowFlags object at 0x7ad0578>

I already knew that

# enable always on top
win.windowFlags() | QtCore.Qt.WindowStaysOnTopHint

# disable it
win.windowFlags() & ~QtCore.Qt.WindowStaysOnTopHint

# toggle it 
win.windowFlags() ^ QtCore.Qt.WindowStaysOnTopHint
like image 255
Shuman Avatar asked Oct 12 '16 19:10

Shuman


1 Answers

The WindowFlags object is an OR'd together set of flags from the WindowType enum. The WindowType is just a subclass of int, and the WindowFlags object also supports int operations.

You can test for the presence of a flag like this:

>>> bool(win.windowFlags() & QtCore.Qt.WindowStaysOnTopHint)
False

or like this:

>>> int(win.windowFlags() & QtCore.Qt.WindowStaysOnTopHint) != 0
False

In general, & returns the value itself when present, or zero when absent:

>>> flags = 1 | 2 | 4
>>> flags
7
>>> flags & 2
2
>>> flags & 8
0
like image 64
ekhumoro Avatar answered Oct 03 '22 14:10

ekhumoro