TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #381 · 23 окт.

Установить свойства виджета в PySide можно не только через соответствующие методы и конструктор класса. Можно их изменять с помощью метода setProperty по имени. btn = QPushButton("Click Me") btn.setProperty("flat", True) Это аналогично вызову btn.setFlat(True) Если указать несуществующее свойство, то оно просто создается btn.setProperty("btnType", "super") Получить его значение можно методом .property(name) btn_type = btn.property("btnType") Когда это может быть полезно? ▫️Можно просто хранить какие то данные в виджете и потом их доставать обратно widget = QWidget() widget.setProperty('my_data', 123) print(widget.property('my_data')) ▫️ Назначая эти свойства разным виджетам можно потом отличить виджеты во время итераци по ним. Например, найти все кнопки со свойством my_data="superbtn". Но ведь вместо кастомного свойства можно использовать objectName, будет тот же результат. Да, но y ObjectName есть ограничение - только строки. ▫️ Если нам потребуется не просто поиск а, например, сортировка по числу, то свойства позволяют нам это сделать. Поддерживается любой тип данных widget.setProperty('my_data', {'Key': 'value'}) widget.setProperty('order', 1) all_widgets.sort(key=w: w.property('order')) Но ведь Python позволяет всё вышеперечисленное сделать простым созданием атрибута у объекта widget.order = 1 widget.my_data = 123 Да, но я думаю что не надо объяснять почему не стоит так делать. К тому же, если у виджета нет свойства то метод .property(name) вернет None, а отсутствующий атрибут выбросит исключение. ▫️ Действительно полезное применение кастомным свойствам - контроль стилей. Здесь атрибутами не обойтись, нужны именно свойства. Дело в том, что в селекторах стилей можно указывать конкретные свойства виджетов на которые следует назначать стиль. Просто запустите этот код from PySide2.QtWidgets import * if __name__ == "__main__": app = QApplication([]) widget = QWidget(minimumWidth=300) layout = QVBoxLayout(widget) btn1 = QPushButton("Action 1") btn2 = QPushButton("Action 2") btn3 = QPushButton("Action 3", flat=True) layout.addWidget(btn1) layout.addWidget(btn2) layout.addWidget(btn3) # добавим кастомное свойство одной кнопке btn1.setProperty("btnType", "super") # добавляем стили widget.setStyleSheet( """ QPushButton[btnType="super"] { background-color: yellow; color: red; } QPushButton[flat="true"] { color: yellow; } """ ) widget.show() app.exec_() С помощью селектора мы избирательно назначили стили на конкретные кнопки. Как получить список всех кастомный свойств? Функция получения списка кастомных свойств отличается от получения дефолтных. def print_widget_dyn_properties(widget): for prop_name in widget.dynamicPropertyNames(): property_name = prop_name.data().decode() property_value = widget.property(property_name) print(f"{property_name}: {property_value}") #tricks#qt

Hashtags

Резултати

Пронајдени 54 слични објави

Пребарај: #gleam

当前筛选 #gleam清除筛选
Genius Airdrops™

@geniusairdropsss · Post #513 · 23.03.2024 г., 16:58

🔥 Baby Slerf Airdrop Event 🎁 Total Airdrop Pool 1,000,000,000 $BSLERF ✅ Complete #gleam https://gleam.io/BZTdD/baby-slerf-airdrop-event Disclaimer: Please do your own research before joining to any airdrops project, also airdrop is 100% free. Don't send any fee or penny for receiving airdrop tokens. Just join airdrop free!

Hashtags

Genius Airdrops™

@geniusairdropsss · Post #511 · 09.03.2024 г., 07:19

🔥 Acti Airdrop Event 🎁 100 $ACTI For ALL ✅ Complete #gleam https://gleam.io/GLdfR/joinactiqsocialmedianew Disclaimer: Please do your own research before joining to any airdrops project, also airdrop is 100% free. Don't send any fee or penny for receiving airdrop tokens. Just join airdrop free!

Hashtags

Genius Airdrops™

@geniusairdropsss · Post #425 · 27.07.2023 г., 15:41

📣 BitCraft Airdrop is live! 🏆 Reward for Tasks: 175 $BLOCK for 2000 random participants each. 👨‍👩‍👧 Referral Reward:50,000 $BLOCK for top 50 referrers. ✅ Complete #gleam https://gleam.io/competitions/tZm7C-bitcraft-airdrop Disclaimer: Please do your own research before joining to any airdrops project, also airdrop is 100% free. Don't send any fee or penny for receiving airdrop tokens. Just join airdrop for free!

Hashtags

Airdropp.io

@airdropp_io · Post #476 · 07.03.2024 г., 18:58

🔥 MetaOasis Momo Airdrop 🚀 Airdrop link : https://t.me/MomoAI_bot/app?startapp=0KHBIB 💳 Wallet : Solana-Ton 💬 What needs to be done: Go to Draw, send it to someone 1 time and then draw! 🚨I ask you to do it, it may be important. #Airdrop#gleam

🙎‍♂️$10,000 Bombie Giveaway on Gleam This activity will be very useful for everyone who plays Bombie. All you need to do is subscribe to Bombie's TG and Twitter. You will also need the Bombie UID — it is behind the avatar on the left bottom corner. 🎁200 Random Winners Will Share $3,000 in $TON 🛷3,000 Random Winners Will Share $7,000 In-Game BTC and Airdrop Boxes Follow the instructions to earn points. The more points you earn, the more chances you have to win prizes! ‼️ Make sure your #Twitter account has a profile photo, otherwise it will be flagged as a spam. Deadline: December 20, 00:00 (UTC+8) #TON#Bombie#Gleam#airdrop

🙎‍♂️$10,000 Bombie Giveaway on Gleam This activity will be very useful for everyone who plays Bombie. All you need to do is subscribe to Bombie's TG and Twitter. You will also need the Bombie UID — it is behind the avatar on the left bottom corner. 🎁200 Random Winners Will Share $3,000 in $TON 🛷3,000 Random Winners Will Share $7,000 In-Game BTC and Airdrop Boxes Follow the instructions to earn points. The more points you earn, the more chances you have to win prizes! ‼️ Make sure your #Twitter account has a profile photo, otherwise it will be flagged as a spam. Deadline: December 20, 00:00 (UTC+8) #TON#Bombie#Gleam#airdrop

Genius Airdrops™

@geniusairdropsss · Post #440 · 18.08.2023 г., 09:36

🔥 Emartzon Airdrop Event 🪂 🎁 Total Airdrop Pool $10,200 Worth $EMZ For 2000 Random Users and Top 20 Referral ✅ Complete #gleam gleam.io/2Ebgn/emartzon… Emartzon aims to revolutionize the world of ecommerce! emartzon.com #Airdrops#Giveaway#crypto#airdrop Disclaimer: Please do your own research before joining to any airdrops project, also airdrop is 100% free. Don't send any fee or penny for receiving airdrop tokens. Just join airdrop for free!

Genius Airdrops™

@geniusairdropsss · Post #457 · 24.09.2023 г., 08:50

🔥DBMETA Blind Box Airdrop🔥 🏆 Total Prize:$1,000,000 DBM ($2000) 🎁 Joining Reward : 30000DB ($18) For all Registed Users of DBMETA APP 👥 Ref reward : $100 worth of DB Token ✅ Complete #gleam https://gleam.io/K9PCz/dbmeta-airdrop #airdrop#airdrops#crypto#airdropcrypto

Airdropp.io

@airdropp_io · Post #461 · 22.01.2024 г., 06:26

🔥 Archloot Airdrop 🚀 Participation link : https://wn.nr/v2SA5Qx 🏆 Winner: 250 💰 Prize: $3000 $ALT 💳 Wallet: Metamask 🚨 Last Day: January 25th Distribution: January 28 💬 Groups You Should Join : https://t.me/archloot #Airdrop#Giveaway#Gleam#Archloot

Genius Airdrops™

@geniusairdropsss · Post #526 · 02.05.2024 г., 10:32

🔥 Dogex AI Airdrop Event 🎁 Total Airdrop Pool $4200 Worth $DOGEXAI ✅ Complete #gleam https://gleam.io/NKCf2/dogex-ai-airdrop-event #Airdrops#Giveaway#crypto#airdropcrypto#airdrop Disclaimer: Please do your own research before joining to any airdrops project, also airdrop is 100% free. Don't send any fee or penny for receiving airdrop tokens. Just join airdrop free!

ПретходнаСтраница 1 од 5Следна