@TestFlightX · Post #34890 · 30.03.2026 г., 17:05
#Soccer - SOOC Photo Sharing https://testflight.apple.com/join/xtrAJCdk
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
Пребарај: #soccer
@TestFlightX · Post #34890 · 30.03.2026 г., 17:05
#Soccer - SOOC Photo Sharing https://testflight.apple.com/join/xtrAJCdk
Hashtags
@wallpapers · Post #5032 · 05.09.2022 г., 13:30
EWallpapers✨ | #Soccer⚽
Hashtags
@maineventnews · Post #116 · 31.07.2024 г., 10:02
Two days ago, Triestina from Serie C sold defender Lorenzo Moretti. However, the club quickly found a replacement by signing his twin brother Andrea. #Soccer 👁Subscribe to Main Event | Sport News
Hashtags
@maineventnews · Post #115 · 31.07.2024 г., 08:02
Yamal is vacationing in Marbella a day after his girlfriend, Alex Padiya, was seen on another guy's lap during an Instagram live stream. #Soccer 👁Subscribe to Main Event | Sport News
Hashtags
@maineventnews · Post #113 · 30.07.2024 г., 20:01
Arsenal announced the transfer of Riccardo Calafiori from Bologna. The transfer fee is £42 million. #Soccer 👁Subscribe to Main Event | Sport News
Hashtags
@maineventnews · Post #112 · 30.07.2024 г., 18:01
Antonella was monitoring what Leo was doing on his phone during the Inter Miami vs. Puebla match. #Soccer 👁Subscribe to Main Event | Sport News
Hashtags
@maineventnews · Post #111 · 30.07.2024 г., 16:01
Manchester United is discussing the construction of a new home stadium with a capacity of 100,000 spectators, costing £2 billion. The club considers the £1.2 billion renovation of Old Trafford to be less advantageous. #Soccer 👁Subscribe to Main Event | Sport News
Hashtags
@maineventnews · Post #110 · 30.07.2024 г., 14:01
Real Madrid is working on signing Trent Alexander-Arnold and Alphonso Davies on free transfers in 2025, according to Matteo Moretto. #Soccer 👁Subscribe to Main Event | Sport News
Hashtags
@maineventnews · Post #107 · 30.07.2024 г., 08:01
Taylor Swift drew over 70,000 fans at the Olympic Stadium in Munich, which hosted the finals of the 1974 World Cup and Euro 1988. Fans who couldn't get tickets listened to the concert from a nearby hill. German police counted 40,000 people there. #Soccer 👁Subscribe to Main Event | Sport News
Hashtags
@maineventnews · Post #106 · 30.07.2024 г., 06:01
Mbappe received a new BMW i7 M70 xDrive worth 186,750 euros from Real Madrid. Perez has the same model. The car has a power output of 660 hp, accelerates from 0 to 100 km/h in 3.7 seconds, features massage seats, and has a top speed of 250 km/h. However, Kylian doesn't have a driver's license. #Soccer 👁Subscribe to Main Event | Sport News
Hashtags
@maineventnews · Post #103 · 23.07.2024 г., 18:02
A warm welcome for Rakitić from Hajduk fans! Ivan specifically broke his contract with Al-Shabab to play for the Split-based club. The 36-year-old footballer will be playing in his native Croatia for the first time in his career. #Soccer 👁Subscribe to Main Event | Sport News
Hashtags
@maineventnews · Post #101 · 23.07.2024 г., 14:02
Raphaël Varane will sign a two-year contract with Como (Fabrizio Romano). The Serie A newcomer already has Reina, Belotti, and Alberto Moreno in their squad, and the club is also trying to sign Martial and Depay. #Soccer 👁Subscribe to Main Event | Sport News
Hashtags