В фреймворке 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 2023, astronomers observed a rare type of supernova explosion in the galaxy NGC 4995, located about 59 million light-years away. Classified as a Type Iax supernova, this unusual blast is thought to be a "partial" explosion where the white dwarf star survives the event—unlike normal supernovae, which completely destroy their stars—offering new insight into the variety of stellar deaths in the cosmos. ✨
#supernovae⚡#ngc4995⚡#stardeath⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 One of the most powerful supernova explosions ever recorded was SN 1006, observed in 1006 AD and visible from Earth for months—even during the daytime. Located about 7,200 light-years away in the constellation Lupus, this supernova was likely caused by a white dwarf star (the dense remnant of a Sun-like star) pulling in material from a companion until it exploded, briefly becoming brighter than Venus and leaving behind a vast, glowing remnant still detected today. ✨
#supernova⚡#Lupus⚡#stardeath⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels