@all_bts_updates · Post #109374 · 13.09.2025 г., 14:41
CORTIS sings happy birthday to #RM during his live on Weverse ! -@All_BTS_Updates
Hashtags
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
Пребарај: #rm
@all_bts_updates · Post #109374 · 13.09.2025 г., 14:41
CORTIS sings happy birthday to #RM during his live on Weverse ! -@All_BTS_Updates
Hashtags
@all_bts_updates · Post #108972 · 24.08.2025 г., 14:16
📊 CHARTS] "Indigo" by #RM now hits 900 Million streams on Spotify...! CONGRATULATIONS NAMJOON CONGRATULATIONS RM -@All_BTS_Updates
Hashtags
@OUR_7_PRINCES · Post #114719 · 19.07.2025 г., 16:44
#RM at the wedding of Kim Youngjin and Lee Hajeong in Seoul. #INFO •@OUR_7_PRINCES•
@OUR_7_PRINCES · Post #114718 · 19.07.2025 г., 16:43
Tae Hoon Lee (Nike’s Korea Marketing Director) shared a picture of #RM with J-Hope and Suga at the wedding. #INFO •@OUR_7_PRINCES•
@OUR_7_PRINCES · Post #113788 · 18.06.2025 г., 23:41
#RM in his session talk for Samsung Art TV at Art Basel. #INFO •@OUR_7_PRINCES•
@OUR_7_PRINCES · Post #113780 · 18.06.2025 г., 23:41
#RM spotted at Art Basel's Messeplatz in Switzerland. #INFO •@OUR_7_PRINCES•
@OUR_7_PRINCES · Post #113774 · 18.06.2025 г., 23:41
#RM spotted at Art Basel's Messeplatz in Switzerland. #INFO •@OUR_7_PRINCES•
@OUR_7_PRINCES · Post #113772 · 18.06.2025 г., 23:26
#RM via Amalia Wirjono (Museum MACAN's Head of Development) instagram. https://www.instagram.com/p/DLDS91PTkYX/?igsh=aGU2ZXc2bGk2cGw2 #INFO •@OUR_7_PRINCES•
@OUR_7_PRINCES · Post #115031 · 01.08.2025 г., 08:42
RM INSTAGRAM STORY UPDATE 💜 Translation Weren’t you curious? You must have been very curious. But writing is something you keep doing because you think you can’t help it, even if you won’t become a good writer. They probably kept writing, and by doing so, they became writers. Now they are probably getting asked the same question I get: ‘Did you always think you’d become a writer?’ If you live like a useless boat drifting with the tide, you eventually arrive somewhere. That is the future. And it comes even if you do nothing. When you finally reach that future, there is something everyone does—rewrite the preface of the past to match the ending [this quote is from a book. It’s attributed to Kim Young-ha (김영하) and appears in his novel A Single Life (단 한 번의 삶) .] #RM | #INSTAGRAM •@OUR_7_PRINCES•
Hashtags
@OUR_7_PRINCES · Post #114745 · 21.07.2025 г., 14:52
RM INSTAGRAM POST UPDATE 💜 🐨: nonchalant #RM | #INSTAGRAM •@OUR_7_PRINCES•
Hashtags
@OUR_7_PRINCES · Post #114717 · 19.07.2025 г., 16:42
Artist Yoon Jiyong shared this picture of #RM on instagram story. #INSTAGRAM •@OUR_7_PRINCES•
Hashtags
@OUR_7_PRINCES · Post #114715 · 19.07.2025 г., 16:42
#RM via rkive repost: 1. Eyes Magazine editor Jin Pyo: “Kim euri @ rkive You’re really a good host/MC.” 2. Post Archive Fasion Creative Director Lim Dongjoon: “You're the best MC/host I've ever seen...” #RM | #INSTAGRAM •@OUR_7_PRINCES•
Hashtags