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

Резултати

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

Пребарај: #argentinosjrs

当前筛选 #argentinosjrs清除筛选
AI match predictions

@ai_match_prediction · Post #12068 · 12.05.2026 г., 17:05

Argentina Liga Profesional Argentina🇦🇷 2026-05-12 22:00 UTC Belgrano Cordoba vs. Union Santa Fe Predicted outcome: Belgrano Cordoba✅ Predicted score: 2:1 Actual: Belgrano Cordoba 2:0 #BelgranoCordoba#UnionSantaFe 2026-05-13 00:30 UTC Argentinos JRS vs. Huracan Predicted outcome: Argentinos JRS❌ Predicted score: 2:1 Actual: Draw 0:0 #ArgentinosJRS#Huracan #Football#ArgentinaLigaProfesional

AI match predictions

@ai_match_prediction · Post #11791 · 27.04.2026 г., 17:05

Argentina Liga Profesional Argentina🇦🇷 2026-04-27 21:45 UTC Velez Sarsfield vs. Union Santa Fe Predicted outcome: Velez Sarsfield❌ Predicted score: 2:1 Actual: Draw 2:2 #VelezSarsfield#UnionSantaFe 2026-04-28 00:00 UTC Huracan vs. Argentinos JRS Predicted outcome: Huracan❌ Predicted score: 2:1 Actual: Argentinos JRS 1:2 #Huracan#ArgentinosJRS #Football#ArgentinaLigaProfesional

AI match predictions

@ai_match_prediction · Post #11355 · 06.04.2026 г., 17:05

Argentina Liga Profesional Argentina🇦🇷 2026-04-06 22:00 UTC Argentinos JRS vs. Banfield Predicted outcome: Argentinos JRS✅ Predicted score: 2:0 Actual: Argentinos JRS 3:2 #ArgentinosJRS#Banfield 2026-04-07 00:15 UTC Instituto Cordoba vs. Defensa Y Justicia Predicted outcome: Defensa Y Justicia❌ Predicted score: 1:2 Actual: Instituto Cordoba 2:0 #InstitutoCordoba#DefensaYJusticia #Football#ArgentinaLigaProfesional

AI match predictions

@ai_match_prediction · Post #11992 · 09.05.2026 г., 13:05

Argentina Liga Profesional Argentina🇦🇷 2026-05-09 19:30 UTC Talleres Cordoba vs. Belgrano Cordoba Predicted outcome: Draw❌ Predicted score: 1:1 Actual: Belgrano Cordoba 0:1 #TalleresCordoba#BelgranoCordoba 2026-05-09 22:00 UTC Boca Juniors vs. Huracan Predicted outcome: Boca Juniors❌ Predicted score: 1:0 Actual: Draw 1:1 #BocaJuniors#Huracan 2026-05-10 00:30 UTC Independ. Rivadavia vs. Union Santa Fe Predicted outcome: Independ. Rivadavia❌ Predicted score: 2:1 Actual: Union Santa Fe 1:2 #IndependienteRivadavia#UnionSantaFe 2026-05-10 01:15 UTC Argentinos JRS vs. Lanus Predicted outcome: Argentinos JRS✅ Predicted score: 2:1 Actual: Argentinos JRS 2:0 #ArgentinosJRS#Lanus #Football#ArgentinaLigaProfesional

AI match predictions

@ai_match_prediction · Post #11575 · 18.04.2026 г., 13:05

Argentina Liga Profesional Argentina🇦🇷 2026-04-18 18:00 UTC Gimnasia L.P. vs. Estudiantes de Rio Cuarto Predicted outcome: Gimnasia L.P.✅ Predicted score: 2:0 Actual: Gimnasia L.P. 1:0 #GimnasiaLP#EstudiantesdeRioCuarto 2026-04-18 20:15 UTC Instituto Cordoba vs. Estudiantes L.P. Predicted outcome: Draw❌ Predicted score: 1:1 Actual: Estudiantes L.P. 0:1 #InstitutoCordoba#EstudiantesLP 2026-04-18 22:30 UTC Independiente vs. Defensa Y Justicia Predicted outcome: Independiente✅ Predicted score: 2:1 Actual: Independiente 3:1 #Independiente#DefensaYJusticia 2026-04-19 00:45 UTC Argentinos JRS vs. Atletico Tucuman Predicted outcome: Argentinos JRS✅ Predicted score: 2:1 Actual: Argentinos JRS 1:0 #ArgentinosJRS#AtleticoTucuman #Football#ArgentinaLigaProfesional

AI match predictions

@ai_match_prediction · Post #11158 · 22.03.2026 г., 13:05

Argentina Liga Profesional Argentina🇦🇷 2026-03-22 18:30 UTC Sarmiento Junin vs. Aldosivi Predicted outcome: Draw❌ Predicted score: 1:1 Actual: Sarmiento Junin 2:0 #SarmientoJunin#Aldosivi 2026-03-22 20:45 UTC Estudiantes de Rio Cuarto vs. River Plate Predicted outcome: River Plate✅ Predicted score: 0:1 Actual: River Plate 0:2 #EstudiantesdeRioCuarto#RiverPlate 2026-03-22 23:00 UTC Boca Juniors vs. Instituto Cordoba Predicted outcome: Boca Juniors✅ Predicted score: 2:0 Actual: Boca Juniors 2:0 #BocaJuniors#InstitutoCordoba 2026-03-23 01:15 UTC Argentinos JRS vs. Platense Predicted outcome: Argentinos JRS✅ Predicted score: 1:0 Actual: Argentinos JRS 1:0 #ArgentinosJRS#Platense 2026-03-23 01:15 UTC Independ. Rivadavia vs. Rosario Central Predicted outcome: Rosario Central❌ Predicted score: 0:1 Actual: Independ. Rivadavia 2:0 #IndependienteRivadavia#RosarioCentral #Football#ArgentinaLigaProfesional

AI match predictions

@ai_match_prediction · Post #11441 · 11.04.2026 г., 13:05

Argentina Liga Profesional Argentina🇦🇷 2026-04-11 18:00 UTC Deportivo Riestra vs. Instituto Cordoba Predicted outcome: Draw❌ Predicted score: 1:1 Actual: Instituto Cordoba 0:1 #DeportivoRiestra#InstitutoCordoba 2026-04-11 18:30 UTC Independ. Rivadavia vs. Argentinos JRS Predicted outcome: Draw❌ Predicted score: 1:1 Actual: Independ. Rivadavia 3:1 #IndependienteRivadavia#ArgentinosJRS 2026-04-11 20:15 UTC Estudiantes L.P. vs. Union Santa Fe Predicted outcome: Estudiantes L.P.✅ Predicted score: 2:1 Actual: Estudiantes L.P. 2:1 #EstudiantesLP#UnionSantaFe 2026-04-11 22:30 UTC Boca Juniors vs. Independiente Predicted outcome: Boca Juniors❌ Predicted score: 1:0 Actual: Draw 1:1 #BocaJuniors#Independiente 2026-04-12 00:45 UTC Estudiantes de Rio Cuarto vs. Barracas Central Predicted outcome: Barracas Central✅ Predicted score: 0:1 Actual: Barracas Central 1:2 #EstudiantesdeRioCuarto#BarracasCentral #Football#ArgentinaLigaProfesional

AI match predictions

@ai_match_prediction · Post #11893 · 03.05.2026 г., 09:05

Argentina Liga Profesional Argentina🇦🇷 2026-05-03 16:30 UTC Aldosivi vs. Independ. Rivadavia Predicted outcome: Independ. Rivadavia❌ Predicted score: 1:2 Actual: Draw 1:1 #Aldosivi#IndependienteRivadavia 2026-05-03 19:00 UTC Belgrano Cordoba vs. Sarmiento Junin Predicted outcome: Belgrano Cordoba✅ Predicted score: 2:1 Actual: Belgrano Cordoba 4:0 #BelgranoCordoba#SarmientoJunin 2026-05-03 19:00 UTC Gimnasia L.P. vs. Argentinos JRS Predicted outcome: Argentinos JRS❌ Predicted score: 1:2 Actual: Gimnasia L.P. 2:0 #GimnasiaLP#ArgentinosJRS 2026-05-03 19:00 UTC Racing Club vs. Huracan Predicted outcome: Racing Club❌ Predicted score: 2:1 Actual: Draw 0:0 #RacingClub#Huracan 2026-05-03 19:00 UTC Rosario Central vs. Tigre Predicted outcome: Rosario Central❌ Predicted score: 2:1 Actual: Draw 1:1 #RosarioCentral#Tigre 2026-05-03 21:30 UTC River Plate vs. Atletico Tucuman Predicted outcome: River Plate❌ Predicted score: 3:1 Actual: Atletico Tucuman 0:1 #RiverPlate#AtleticoTucuman #Football#ArgentinaLigaProfesional