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

Резултати

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

Пребарај: #independiente

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

@ai_match_prediction · Post #11286 · 04.04.2026 г., 09:06

Argentina Liga Profesional Argentina🇦🇷 2026-04-04 16:30 UTC Aldosivi vs. Estudiantes de Rio Cuarto Predicted outcome: Aldosivi❌ Predicted score: 1:0 Actual: Draw 0:0 #Aldosivi#EstudiantesdeRioCuarto 2026-04-04 20:30 UTC Independiente vs. Racing Club Predicted outcome: Draw❌ Predicted score: 2:2 Actual: Independiente 1:0 #Independiente#RacingClub 2026-04-05 00:00 UTC Rosario Central vs. Atletico Tucuman Predicted outcome: Rosario Central✅ Predicted score: 2:1 Actual: Rosario Central 2:1 #RosarioCentral#AtleticoTucuman #Football#ArgentinaLigaProfesional

AI match predictions

@ai_match_prediction · Post #12029 · 10.05.2026 г., 13:05

Argentina Liga Profesional Argentina🇦🇷 2026-05-10 18:00 UTC Rosario Central vs. Independiente Predicted outcome: Rosario Central✅ Predicted score: 2:1 Actual: Rosario Central 3:1 #RosarioCentral#Independiente 2026-05-10 20:00 UTC Estudiantes L.P. vs. Racing Club Predicted outcome: Estudiantes L.P.❌ Predicted score: 2:1 Actual: Racing Club 0:1 #EstudiantesLP#RacingClub 2026-05-10 22:00 UTC River Plate vs. San Lorenzo Predicted outcome: River Plate❌ Predicted score: 2:0 Actual: Draw 1:1 #RiverPlate#SanLorenzo 2026-05-11 00:30 UTC Velez Sarsfield vs. Gimnasia L.P. Predicted outcome: Velez Sarsfield❌ Predicted score: 2:1 Actual: Gimnasia L.P. 0:1 #VelezSarsfield#GimnasiaLP #Football#ArgentinaLigaProfesional

AI match predictions

@ai_match_prediction · Post #11863 · 02.05.2026 г., 13:05

Argentina Liga Profesional Argentina🇦🇷 2026-05-02 17:30 UTC Lanus vs. Deportivo Riestra Predicted outcome: Lanus❌ Predicted score: 1:0 Actual: Draw 0:0 #Lanus#DeportivoRiestra 2026-05-02 19:15 UTC Central Cordoba de Santiago vs. Boca Juniors Predicted outcome: Boca Juniors✅ Predicted score: 1:2 Actual: Boca Juniors 1:2 #CentralCordobadeSantiago#BocaJuniors 2026-05-02 21:45 UTC San Lorenzo vs. Independiente Predicted outcome: San Lorenzo❌ Predicted score: 2:1 Actual: Independiente 1:2 #SanLorenzo#Independiente 2026-05-02 21:45 UTC Union Santa Fe vs. Talleres Cordoba Predicted outcome: Talleres Cordoba❌ Predicted score: 1:2 Actual: Draw 1:1 #UnionSantaFe#TalleresCordoba #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 #11704 · 24.04.2026 г., 13:06

Argentina Liga Profesional Argentina🇦🇷 2026-04-24 20:00 UTC Deportivo Riestra vs. Independiente Predicted outcome: Draw❌ Predicted score: 1:1 Actual: Deportivo Riestra 2:0 #DeportivoRiestra#Independiente 2026-04-24 22:15 UTC Lanus vs. Central Cordoba de Santiago Predicted outcome: Lanus❌ Predicted score: 2:0 Actual: Draw 0:0 #Lanus#CentralCordobadeSantiago 2026-04-24 22:15 UTC Estudiantes de Rio Cuarto vs. Rosario Central Predicted outcome: Rosario Central✅ Predicted score: 0:2 Actual: Rosario Central 1:2 #EstudiantesdeRioCuarto#RosarioCentral 2026-04-25 00:30 UTC Platense vs. San Lorenzo Predicted outcome: Draw❌ Predicted score: 1:1 Actual: San Lorenzo 0:1 #Platense#SanLorenzo 2026-04-25 00:30 UTC Racing Club vs. Barracas Central Predicted outcome: Racing Club❌ Predicted score: 1:0 Actual: Draw 1:1 #RacingClub#BarracasCentral #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 #11131 · 21.03.2026 г., 13:05

Argentina Liga Profesional Argentina🇦🇷 2026-03-21 18:30 UTC Velez Sarsfield vs. Lanus Predicted outcome: Velez Sarsfield❌ Predicted score: 1:0 Actual: Lanus 0:1 #VelezSarsfield#Lanus 2026-03-21 20:45 UTC Defensa Y Justicia vs. Union Santa Fe Predicted outcome: Union Santa Fe❌ Predicted score: 1:2 Actual: Defensa Y Justicia 2:0 #DefensaYJusticia#UnionSantaFe 2026-03-21 20:45 UTC Newells Old Boys vs. Gimnasia M. Predicted outcome: Draw❌ Predicted score: 1:1 Actual: Newells Old Boys 1:0 #NewellsOldBoys#GimnasiaM 2026-03-21 23:00 UTC Independiente vs. Talleres Cordoba Predicted outcome: Independiente❌ Predicted score: 2:1 Actual: Talleres Cordoba 1:2 #Independiente#TalleresCordoba 2026-03-22 01:15 UTC Belgrano Cordoba vs. Racing Club Predicted outcome: Draw❌ Predicted score: 1:1 Actual: Racing Club 1:2 #BelgranoCordoba#RacingClub #Football#ArgentinaLigaProfesional