В фреймворке 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
🪐 Deep in the Milky Way, the star J0247-25B is a true cosmic oddball—it’s a rare "pre-helium white dwarf," meaning it’s caught in the act of shedding its outer layers before becoming a typical white dwarf star. This unusual star is much hotter than normal for its size, giving scientists a unique chance to watch stellar evolution unfold before their eyes and providing clues about how stars change shape and temperature toward the end of their lives. ✨
#unusualstars⚡#milkyway⚡#white⚡#dwarfs⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 One of the most unusual stars known is SDSS J122859.93+104032.9, a "carbon-rich white dwarf" about 1,000 light-years from Earth. Unlike typical white dwarfs—stellar remnants made mostly of hydrogen and helium—this star's atmosphere is packed with carbon, giving it a faint, bluish glow and defying expectations about how dying stars shed their outer layers. ✨
#unusualstars⚡#white⚡#dwarfs⚡#stardust⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The star HD 49798, located about 2,000 light-years away in the constellation Puppis, is an unusual subdwarf that forms a pair with a mysterious, ultra-dense white dwarf companion. The white dwarf is spinning at a record-breaking speed of just 13 seconds per rotation, making it one of the fastest-spinning white dwarfs ever found and offering a glimpse into rare, exotic outcomes of stellar evolution. ✨
#unusualstars⚡#white⚡#dwarfs⚡#HD49798⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels