В фреймворке 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 forests of Cameroon, the goliath frog boasts the title of world’s largest frog—growing up to 32 centimeters and weighing over 3 kilograms. This gentle giant even builds its own small ponds by moving stones, creating safe nurseries for its tadpoles. ✨
#amphibian⚡#wildlife⚡#adaptation
👉subscribe Interesting Planet
🌎 The wood frog (Rana sylvatica) survives winter by freezing solid, stopping its heartbeat and breathing for months. It produces special proteins and glucose that act as antifreeze, protecting its cells until it thaws and comes back to life in spring. ✨
#adaptation⚡#amphibian⚡#survival
👉subscribe Interesting Planet
👉more Channels
🌎 The wood frog survives Alaskan winters by freezing solid—its heart stops, and ice crystals form inside its body. Special proteins protect its cells until spring, when it thaws and hops away. Some populations can survive temperatures as low as -18°C. ✨
#adaptation⚡#amphibian⚡#freeze
👉subscribe Interesting Planet
🌎 The blue poison dart frog flashes vivid color as a warning—its skin holds toxins strong enough to deter most predators in the wild rainforest. Bright hues like these signal “stay away” in nature’s visual language. ✨
#amphibian⚡#rainforest⚡#color
👉subscribe Interesting Planet
🌎 The “ghost frog” of South Africa spends its life in icy, fast-flowing mountain streams. Its uniquely webbed toes and sticky pads let it grip slippery rocks, helping it thrive in waters too cold and rough for most frogs. ✨
#amphibian⚡#adaptation⚡#streams
👉subscribe Interesting Planet
🌎 The giant salamander of China is the world’s largest amphibian, reaching 1.8 meters in length. Its ancestors appeared about 170 million years ago, and it can live over 50 years in the wild. ✨
#salamander⚡#fossil⚡#amphibian
👉subscribe Interesting Planet
👉more Channels