В фреймворке 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 Puppis, the star RX J1856.5−3754 stands out as the closest known isolated neutron star to Earth. This ultra-dense remnant emits a ghostly blue glow, its surface heated to over 700,000°C, and its powerful magnetic field twists space and time in the surrounding void. ✨
#neutronstars⚡#mysteries⚡#Puppis
👉subscribe Universe Mysteries
🪐 The twin pulsars PSR J0737−3039A and B, located about 2,400 light-years away in the constellation Puppis, are a real-world testing ground for time dilation in space. As these two ultra-dense neutron stars orbit each other at high speeds and within extremely strong gravitational fields, their clocks run at noticeably different rates than those on Earth—showcasing how both high speed and intense gravity stretch and slow down time, just as predicted by Einstein’s theory of relativity. ✨
#timedilation⚡#pulsars⚡#puppis⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels