Установить свойства виджета в 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
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce Our #BinanceLive AMA with BOSS || 5th January 2025 at ( 1:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 5th January , 2026 at (1:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Project Team
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉BOSS
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝Clarnium on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
⏰ Must Join " BOSS Social Media Links :
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with Stake Cash Coin(SACO) || 1st December, 2025 at ( 2:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 1st December , 2025 at (2:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Project Team
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉Stake Cash Coin(SACO)
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝Stake Cash Coin(SACO) on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/live/video?roomId=2285385
⏰ Must Join " Stake Cash Coin(SACO)" Social Media Links :
❌Twitter
✉️Telegram
🌐Website
📷Instagram
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with AIO protocol || 21th November , 2025 at ( 1:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 21th November , 2025 at (1:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Chloe & Jade
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉AIO protocol
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝AIO protocol on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2283711
⏰ Must Join " AIO protocol" Social Media Links :
❌Twitter
✉️Telegram
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with GIGGLE FUND || 16th November , 2025 at ( 6:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 16th November , 2025 at (6:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest :
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉GIGGLE FUND
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝GIGGLE FUND on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
⏰ Must Join " GIGGLE FUND" Social Media Links :
❌Twitter
🔥Website
✉️Telegram
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with Usd1swap || 13th November , 2025 at ( 1:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 13th November , 2025 at (1:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest :
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉Usd1swap
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝Usd1swap on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2283379
⏰ Must Join " Usd1swap" Social Media Links :
❌Twitter
🔥Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with MetaPi || 10th November , 2025 at ( 2:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 10th November , 2025 at (2:00PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Caitlyn
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉MetaPi
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝MetaPi on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2283001
⏰ Must Join " MetaPi" Social Media Links :
❌Twitter
🔥Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with MetaPi || 14th October , 2025 at ( 2:00 PM UTC)
🔠
🔠
🔠
🔠🔠🔠
🔠🔠
🔠🔠
⏳ Time : 14th October , 2025 at (2:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Caitlyn
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉MetaPi
✅Like & Retweet✅Twitter Post
✅ Follow
📝CryptoFight &
📝MetaPi on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/live/video?roomId=2280210
⏰ Must Join " MetaPi" Social Media Links :
❌Twitter🔥Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram✉️Channel
📝Twitter🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with Biokript-Bro || 09th October , 2025 at ( 3:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 09th October , 2025 at (3:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Adnan Alisic, CEO, Adnan_Biokript
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉Biokript-Bro
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝Biokript-Bro on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2280011
⏰ Must Join " Biokript-Bro" Social Media Links :
❌Twitter
✉️Telegram
🔥Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with "CDL" at 11th February 2025 at ( 4:PM, UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 11th February 2025 ( 4: PM, UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 50$ USDT
🤵♂️Guest : CDL Team
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉CDL
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝CDL on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2249344
⏰ Must Join "CDL" Social Media Links :
✉️Telegram
📝Twitter
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with "EvolveToken" at 3th February 2025 at ( 2:PM, UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 3th February 2025 ( 2:00 PM, UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Seth Founder Of Evolve
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉EvolveToken
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝EvolveToken on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2248252&utm_campaign=binance_live
⏰ Must Join "EvolveToken" Social Media Links :
✉️Telegram
📝Twitter
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with "StohnCoin" at 6th February 2025 at (3 PM, UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 6th February 2025 ( 3:00 PM, UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Ing. Jozef Libant - CEO / Brett Weigel - COO / Jason Stanley - CIO / Alexander Almkvist - CTO
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝StohnCoin on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2248211
⏰ Must Join "StohnCoin" Social Media Links :
📝Twitter
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with "POPG" at 21th February 2025 at ( 12 PM, UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 21th February 2025 ( 12 PM, UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Petra Apostolovic - PR & Community and Gabriel Raimundi - Marketing
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉POPG
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝POPG on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2247598
⏰ Must Join "POPG" Social Media Links :
✉️Telegram
📝Twitter
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight