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

Резултати

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

Пребарај: #concept

当前筛选 #concept清除筛选
Car News

@car_news · Post #1269 · 15.05.2025 г., 12:04

🛸This is futuristic: the Hyperion XP-1 hydrogen car with the sound of a spaceship and steam instead of exhaust 🐎 The engine has 2038 hp and acceleration to 100km/h is 2.2 sec. 🔋 One tank of hydrogen helps to overcome in the region of 1600 km. 💰 They are preparing 300 copies, each of which will cost $2 million. #concept@Car_News

Hashtags

Ares Channel

@ArashRx · Post #417 · 19.01.2024 г., 19:10

🅰Request For Approval Telegram in version 10.6.1 added the ability to restrict incoming messages for Non-Premium subscribers, which creates many restrictions for chats. Read more details in the next post. 🌚Concept designed by @Rxdvl (Still me) -#concept 🅰@ArashRx

Hashtags

Ares Channel

@ArashRx · Post #359 · 13.11.2023 г., 13:49

🅰Emoji Switcher, Hold on an emoji to choose custom emojis Yeah, again a concept, even though it shouldn't be. But this time was @Linus's idea; One of his creative ideas. Designed by me🌚 - #concept 🅰@ArashRx

Hashtags

Ares Channel

@ArashRx · Post #292 · 06.08.2023 г., 20:57

🅰Telegram Drive Concept📥 Telegram Drive is an unlimited storage based on cloud space which, in addition to Saved Messages, has features such as editing images before sending and sending them as albums. Write your opinion about this concept in the comments 🌚Designed by me - #concept 🅰️@ArashRx

Hashtags

Ares Channel

@ArashRx · Post #243 · 19.05.2023 г., 09:13

🅰Telegram Moments Concept🔥 Write your opinion about this feature in the comments 🌚Designed by me - #concept 🅰@ArashRx

Hashtags

Ares Channel

@ArashRx · Post #191 · 05.01.2023 г., 16:42

My first concept for Telegram: 🅰Hashtag Notifications Concept🚀 ※ Select the hashtags you want to join be notified about and get notified when those hashtags are posted in a channel🔥 This is only a concept designed by me and it was sent as a suggestion for Telegram and I hope that this concept will be supported so that we can see this feature in Telegram soon. Write your comments about this concept below this post👇 - #concept ⭕️@ArashRx

Hashtags

DWF Labs Broadcast

@Dwflabs · Post #136 · 09.01.2023 г., 00:21

In our latest episode of DWF Chats, we hosted Ty Blackard, Co-founder and Head of Business Development of NFTY Finance 🙌 Hear more about NFTY Finance, how #defi is changing the #concept of credit score and what's coming up for them in 2023 ✨ Full interview here. Click here to find out more. Get connected 💬 Twitter | Linkedin | Website | Discord

Car News

@car_news · Post #1204 · 17.04.2025 г., 14:32

🎮 Sony has revealed Afeela electric car, which can be driven with the PS5 joystick ℹ️ The Afeela concept was originally stated to have 400kW (536hp) dual-motor all-wheel-drive, 0-100km/h in 4.8 seconds, and a top speed of 240km/h. 💰 Still no information on price or battery size, but there are two more years until this car hits the road, so price will surely come later. @CarsNews #concept#EV

Hashtags

Kpop Premium 《🌿》

@bubbletealuv · Post #3382 · 09.10.2025 г., 21:05

ᝬ 🫐🫐🫐🫐🫐𖠵 ゛ (( 🤩) new post by bubbletealuv ↝ #concept ➛ #TXT.. ✨ …( emoji ) 💭 взяли? буду рад увидеть плюсы и реакции.

Hashtags

123•••78
ПретходнаСтраница 1 од 8Следна