В фреймворке 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 Shenzhen, China, nearly all public buses and taxis run on electricity, making it the world’s first major city to fully switch its urban transit fleet to electric vehicles. ✨
#urbangeography⚡#transport⚡#innovation⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Melbourne, Australia, is regularly ranked as one of the world’s most liveable cities thanks to its blend of extensive parks, creative laneways, and a tram network that covers over 250 kilometers. ✨
#urbangeography⚡#citylife⚡#infrastructure⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 The world’s tallest residential building, Central Park Tower in New York City, rises 472 meters. Ultratall skyscrapers like this change city skylines and challenge how we design urban living spaces. ✨
#urbangeography⚡#skyscraper⚡#citylife⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In Seoul, over half the city’s rooftops host gardens, solar panels, or small farms—turning unused urban spaces into green zones that cool neighborhoods and boost local food production. ✨
#urbangeography⚡#cityplanning⚡#greencities⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels