Регулярно приходится писать и ревьюить код, где используется PySide2-6.
Заметил, что в подавляющем большинстве случаев настройка создаваемых базовых виджетов происходит через методы. Думаю, всем знаком такой способ.
Простой пример с кнопкой:
button = QPushButton("Click Me")
button.setMinimumWidth(300)
button.setFlat(True)
button.setStyleSheet("font-size: 20pt")
button.setToolTip("Super Button")
button.clicked.connect(lambda: print("Button clicked"))
Но есть и альтернативный способ - настройка через свойства. Это просто ключевые аргументы конструктора класса. Хоть они и не указаны в документации как аргументы, но они есть)
Этот код делает тоже самое но с помощью Property
button = QPushButton(
"Click Me",
minimumWidth=300,
flat=True,
styleSheet="font-size: 20pt",
toolTip="Super Button",
clicked=lambda: print("Button clicked"),
)
Где это может быть полезно
▫️ Это выглядит более аккуратно и коротко, уже повод использовать
▫️ Может использоваться в заполнении лейаута, когда нам не нужно никакое другое взаимодействие с виджетом и поэтому сохранять его в переменную не требуется. Например, лейбл или кнопка.
widget = QWidget(minimumWidth=400)
layout = QHBoxLayout(widget)
layout.addWidget(QLabel("Button >", alignment=Qt.AlignRight))
layout.addWidget(QPushButton("Click Me", clicked=lambda: print("Button clicked")))
widget.show()
Либо так
widget = QWidget(minimumWidth=400)
layout = QHBoxLayout(widget)
for wd in (
QLabel("Button >", alignment=Qt.AlignRight),
QPushButton("Click Me", clicked=lambda: ...)
):
layout.addWidget(wd)
widget.show()
▫️ Можно хранить настройки в каком-то конфиге или генерировать на лету, после чего передавать как kwargs.
kwargs = {"text": "Hello " * 30, "wordWrap": True}
my_label = QLabel(**kwargs)
Как получить полный список доступных свойств?
Эта функция распечатает в терминал все свойства виджета и их текущие значения
def print_widget_properties(widget):
meta_object = widget.metaObject()
for i in range(meta_object.propertyCount()):
property_ = meta_object.property(i)
property_name = property_.name()
property_value = property_.read(widget)
print(f"{property_name}: {property_value}")
#tricks#qt
🏆 2026 ASIA STAR ENTERTAINER AWARDS
ASEA Fan Choice Singer 🎤
🗓️ Ends: 17 May 2026
📱 My1Pick App
Link : Voting Link
fsn-app.my1pick.com/app/link/theme…
📱 Podoal App
Link : Voting Link
global.podoal.io/app/fandings/5…
📱 Mubeat App
Link : Voting Link
mubeat.applink.info/9hFE0waZsG
📍Check Comment Box for Tutorial
🤍💫 | #voting
@foreverbulletproof7
🏆 MUSIC AWARDS JAPAN
Best of Listeners’: International Song by Spotify
📣 Vote for DSYLM in Music Awards Japan Best of Listeners’ Choice!! 🏃♀️🫷
🗳️ 2 vts for Premium | 1 vt for Non-Premium
📆 Final voting ends on May 20
Link : open.spotify.com/playlist/37i9d…
📍Check Comment Box for Tutorial
🤍💫 | #voting
@foreverbulletproof7
🏆 SEOUL MUSIC AWARD 2026
BTS are nominated in 3 categories:
🏆 Korea Wave Award:
Link : promo-web.idolchamp.com/app_proxy.html…
🏆 Popularity Award:
Link : promo-web.idolchamp.com/app_proxy.html…
🏆 K-pop World Choice - Group:
Link : promo-web.idolchamp.com/app_proxy.html…
📝 Criteria: 100% voting
⏰ Ends May 28, 2026 23:59 (KST) on Idol Champ
📍Check Comment Box for Tutorial
🤍💫 | #voting
@foreverbulletproof7
🏆 Seoul Music Awards
🛑 Focus your votes on Korea Wave Award category!
⇢ Korea Wave Award - #1 BTS 57.85%
App: Idol Champ
Period: 05.08~05.28
Result: sum of all rounds
🤍💫 | #voting
@foreverbulletproof7
[🏆 2026 ASIA STAR ENTERTAINMENT AWARDS]
🛑 5 DAYS LEFT for Fan Choice Singer Final Voting
👉🏻 Status 🚨
▶️ Mubeat #4
▶️ Podoal #7 🔺
▶️ My1Pick #6 🔺
▶️ 100% Voting
▶️ until 5/17
🤍💫 | #voting
@foreverbulletproof7
Everyone please vote for BTS for Forbes Popularity on Mnet plus.
Voting is super easy, We do not have much time.
🔻 : https://play.google.com/store/apps/dev?id=4990449589140386036
🤍💫 | #voting
@foreverbulletproof7
The winners of AMAs will be announced at the AMAs Award Show 💜
⏰ DATE | TIME:
🇺🇸 May 25 at 8PM ET
🇺🇸 May 26 at 9AM KST
🤍💫 | #voting
@foreverbulletproof7
VOTE FOR BTS FOR FORBES POWER 40 CELEBRITY 2026
We’re falling behind fast 🔴 and the gap won’t close on its own
Start collecting MplePoints and cast your votes for BTS! 🌊🏄♂️
LINK : mnetplus.onelink.me/TRa8/xohkwx0b?…
🤍💫 | #voting
______
@foreverbulletproof7
______
BTS has been nominated for the ‘Power Celebrity 40’ list by Forbes Korea.
🏆 Prizes:
• Trophy
• Online PR
• Feature in Forbes Korea Magazine
📲 Vote via Mnet Plus App
Vote here: mnetplus.onelink.me/TRa8/xohkwx0b?…
Ends: May 10, 11:59PM KST
🤍💫 | #voting
@foreverbulletproof7
⚖️🗳️SUPREME COURT CASE COULD RESHAPE VOTING RIGHTS ACT
🔹 Louisiana v Callais challenges constitutionality of Section 2 of Voting Rights Act 📋
🔹 Case targets law prohibiting electoral discrimination based on race nationwide ⚡
🔹 Ruling against could eliminate or dilute Black and Hispanic-majority districts 💀
🔹 Up to nineteen Democratic-held seats primarily in the South at risk 🚨
🔹 Florida, Kentucky, Virginia pursuing mid-decade redistricting before midterms 🗺️
🔹 Governor DeSantis calls special legislative session for April redistricting 🏛️
Major implications for November midterms and minority representation 🔥📊
#USNews#voting
Trending Apps: Enhance Voting with Your Feedback
#Voting#Apps
Trending Apps introduces a new Voting feature and seeks user feedback to improve it. Users can report bugs, suggest improvements, or share ideas to help refine the Apps Center.
Source: link
@tonlines