В фреймворке PyQt (и PySide тоже) часто встречается настройка чего-либо с помощью так называемых флагов.
widget.setWindowFlags(Qt.Window)
Взаимодействие нескольких флагов делается с помощью бинарных (или побитовых) операторов.
Несколько флагов можно указать с помощью оператора "|"
list_item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
исключить флаг из уже имеющегося набора можно так
list_item.setFlags(list_item.flags() ^ Qt.ItemIsEnabled)
Добавить новый флаг к имеющимся можно так
list_item.setFlags(list_item.flags() | Qt.ItemIsEnabled)
А проверка наличия делается так
is_enabled = item.flags() & Qt.ItemIsEnabled > 0
Почему именно так? Всё дело в том как именно работают побитовые операторы. Но об этом в следующем посте.
#qt
🪐 In the constellation Hydra, astronomers have found R Hydrae, a star that pulses in brightness over a period of about 385 days. This "Mira variable" expands and contracts like a cosmic heartbeat, changing size and light output as it nears the end of its life, giving scientists clues about the future fate of our own Sun. ✨
#stars⚡#hydra⚡#pulsation⚡#nasa⚡#galaxy⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 In the constellation Vela, the star system HD 74423 displays an unusual cosmic phenomenon: its shape is teardrop-like rather than round, caused by the powerful gravitational pull of a nearby red dwarf companion. This distortion leads to "heartbeat" pulsations—brightenings and dimmings in rhythm with the stars’ orbits—making HD 74423 the first known one-sided pulsating star in our galaxy. ✨
#Vela⚡#heartbeatstars⚡#pulsation⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries