How to test if WindowStaysOnTopHint flag is set in windowFlags?
Asked Answered
V

1

6

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
Vaduz answered 12/10, 2016 at 19:9 Comment(0)
B
6

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
Bowie answered 12/10, 2016 at 20:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.