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

Резултати

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

Пребарај: #gateiostartup

当前筛选 #gateiostartup清除筛选
Walken.io - Announcement

@walken_channel · Post #244 · 23.07.2022 г., 14:09

🤑Gate.io Startup Answer & Earn @walken_io💵 📝Take the quiz about Walken(WLKN) & Split a $3,000 mega prize!🏆 ⏰Ends at 9:00AM, Jul 25th (UTC) *How to participate: ✅ Join GateioOfficialNews and Walken community ✅Follow @Gateio_Startup & RT the 👉POST 🔛 Click 👉HERE to Participate now Learn More:https://www.gate.io/startup #Gateio#gateiostartup

BYIN Channel

@byinchan · Post #122 · 07.09.2024 г., 06:48

📣Startup Voting Campaign #4 - $8,000 up for grabs Vote for your favorite project by 6:00 AM, Sep 8 (UTC)! 🏆Winning projects will shine in the spotlight! 💎$BYIN$CEC$MAK$ANS 🔄Share to rally support for your pick! 👉Vote:https://gate.io/activities/startupvote?gt_disable_intercept_jump=1&now_period=5 #GateioStartup#Memecoins#Airdrop

BYIN Channel

@byinchan · Post #111 · 05.09.2024 г., 15:25

📣Day 3 of voting! $8,000 up for grabs—vote for your favorite project by 6:00 AM, Sep 8 (UTC)! 🏆Winning projects will shine in the spotlight! 💎$BYIN$CEC$MAK$ANS 🔁Share to rally support for your pick! 👉Vote:https://gate.io/activities/startupvote?gt_disable_intercept_jump=1&now_period=5 #GateioStartup#Memecoins#Airdrop

BYIN Channel

@byinchan · Post #106 · 04.09.2024 г., 09:48

🚀$8,000 up for grabs! #Vote for your favorite project by 06:00 AM, Sep 8 (UTC)! $BYIN$CEC$MAK$ANS 🏆Winning projects get the spotlight 🔁Retweet to support your pick Vote now:https://gate.io/activities/startupvote?gt_disable_intercept_jump=1&now_period=5 #GateioStartup#Memecoins#Airdrop

Holdcoin Channel

@Holdcoin_Channel · Post #309 · 11.12.2024 г., 12:59

📣Gate.io #StartupMining Initial Offering:HoldCoin (HOLD) ❇️Total Rewards: 73,333,333 $HOLD ❇️Estimated APR: 1241% 1⃣Stake $USDT & $GT from 01:00pm, Dec 11 (UTC) https://www.gate.io/startup-mining/HOLD?pid=111 2⃣Stake $HOLD and $GT from 01:00pm, Dec 16(UTC) https://www.gate.io/startup-mining/HOLD?pid=112 3⃣Stake $HOLD and $GT from 01:00pm, Dec 26(UTC) https://www.gate.io/startup-mining/HOLD?pid=113 📈Trading Starts: 13:00pm, Dec 16 (UTC) More:https://gate.io/announcements/article/41542 #Gateio#GateioStartup#Farming

Your Own Ads

@yourownads · Post #190 · 12.02.2025 г., 12:09

📈#Gateiopartner carnival: the main prize of $12,000 is being played out 🔥 The promotion is active until 11:00 Moscow time on February 24 ℹ️How to earn: 1) Registration on Gate + KYC2 2) Go here and click "Join now" 3) We complete the tasks: 🎁BONUS 1 : Registration + KYC, PrizeStartup voucher for 20 shares 🎁BONUS 2 : Make a deposit of $50, prize from $5 to $10 🎁BONUS 3 : Make a trading volume of $200, split the prize pool of $10,000 depending on the share in the total trading volume 🎁BONUS 4 : Invite users and share the prize pool of $2000 🔗Join now and earn: https://gate.io/fr/campaigns/396?ref=VLJMULHBVA #Gateio#GateioStartup#Crypto

Your Own Ads

@yourownads · Post #149 · 06.01.2025 г., 20:26

🚀Gate.io Startup Free Offering: Cat Gold Miner (CATGOLD) 🗓Subscription Period:06:00AM January 7 - January 9 (UTC) 💵Airdrop Amount: $50,000 CATGOLD 👉Sign up here 🔗 ⏰Trading Starts:10:00,AM January 9 (UTC) 📚Full Details:Click here 🎉Gate.io New Year Red Envelope: Get a $60 bonus by following this link ➜ Red Envelope ⚡️Don’t miss this unique chance to accelerate your earnings with CATGOLD! Places are limited, register now and be among the first to take advantage of this exclusive offer! ⭐️ 🔗gate.io 📈 #GateioStartup#Gateio#CATGOLD

Your Own Ads

@yourownads · Post #187 · 08.02.2025 г., 16:29

💰Trade $HQ on Gate.io & Win Your Share of $4,000! 👀 A new trading event is live on Gate.io, giving you the chance to earn big rewards! 🗓Event Period: February 7 at 06:00 AM UTC - February 12 at 06:00 AM UTC 💰Rewards: ✅$3,000 Trading Bonus – Trade at least $50 in HQ and share a $3,000 prize pool. ✅$950 New User Bonus – New users who sign up and trade $10 in HQ will receive $10 instantly. ✅$50 Lucky Reward – 1 lucky participant from the comments will win $50! ⚠️Important: ✔️ Complete your identity verification before the event ends to qualify. ✔️ Rewards will be distributed in HQ within 14 working days. ✔️ No multiple accounts or fraudulent activity allowed. 🔥Join now and start trading! Don’t miss your chance to win big! 🔗Sign up & start trading here: https://www.gate.io/signup/?ref_type=103 #Gateio#GateioStartup#StartupMining#Launchpool#Launchpad