Shuman
Shuman

Reputation: 4132

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

Upvotes: 6

Views: 2020

Answers (1)

ekhumoro
ekhumoro

Reputation: 120768

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

Upvotes: 6

Related Questions