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

Резултати

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

Пребарај: #nasrallah

当前筛选 #nasrallah清除筛选
Libertà è ragione

@libertaeragione · Post #4248 · 28.09.2024 г., 08:33

#Israele#Libano Capo di Stato Maggiore dell’#IDF: “La morte di Hassan #Nasrallah non è la fine delle nostre azioni. Il messaggio è semplice: chiunque minacci i cittadini dello Stato di Israele sapremo come raggiungerlo”. @OsservatorioEsteri

Red Nile

@rednile12 · Post #11265 · 15.03.2026 г., 14:14

OSINT leaks - Syrian Mossad spy taking refuge in Lebanon's Ukrainian embassy. A terrorist with Syrian, Ukrainian and Israeli citizenship. He helped in killing Hassan Nasrallah and other terrorist attack. Credits: Journalist Radwan Mortada @cKure #Lebanon#Nasrallah#Mossad#Ukraine#Hezbollah

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #4074 · 26.02.2025 г., 07:51

A historic funeral procession was held in Beirut on Sunday for late Hezbollah chiefs Hassan Nasrallah and Hashem Safieddine who were assassinated by Israel late last year. Although Israeli fighter jets flew twice at a low altitude over the hundreds of thousands crowded to mourn the Hezbollah chiefs, the masses stood unwavering chanting “Death to Israel.” #Nasrallah#NasrallahFuneral#Hezbollah#Lebanon#Israel

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #4053 · 24.02.2025 г., 21:29

A historic funeral procession was held in Beirut on Sunday for late Hezbollah chiefs Hassan Nasrallah and Hashem Safieddine who were assassinated by Israel late last year. Although Israeli fighter jets flew twice at a low altitude over the hundreds of thousands crowded to mourn the Hezbollah chiefs, the masses stood unwavering chanting “Death to Israel.” #Nasrallah#NasrallahFuneral#Hezbollah#Lebanon#Israel

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3447 · 11.10.2024 г., 17:51

Journalist and geopolitical analyst Fiorella Isabel @FiorellaInMoscow tackles the latest Israeli war crimes in Gaza and Lebanon. She underlines that the assassination of Hezbollah Chief Hassan Nasrallah created more support for the Lebanese group, and that thousands of his likes will be created to fight Israel back. #Hezbollah#Nasrallah#Lebanon#Gaza#Palestine#Netanyahu#Israel

White House Watch

@WhiteHouseWatch · Post #18278 · 17.03.2026 г., 20:58

#Iran L’agenzia stampa Fars, conferma la notizia che il Segretario del Consiglio Supremo per la Sicurezza Nazionale Ali #Larijani sia morto a seguito dell’attacco israeliano. “Ali Larijani, Segretario del Consiglio Supremo per la Sicurezza Nazionale, è stato martirizzato. […] Le anime pure dei martiri hanno accolto l'anima pura di Abdul Saleh God, il martire Dr. Ali Larijani, che, dopo una vita di lotta per il progresso dell'Iran e della Rivoluzione Islamica, ha finalmente realizzato il suo desiderio di lunga data, ha risposto alla chiamata della verità e ha orgogliosamente raggiunto la grazia del martirio nelle trincee del servizio. Egli si unì all'Imam dei Martiri del Ramadan, il Comandante dei Credenti Ali (pace su di lui), e al leader della carovana del martirio e del jihad contro l'America e Israele, Sua Santità l'Ayatollah Seyyed Ali #Khamenei, al suo maestro martire, Sua Santità il Maestro Ayatollah Motahari, e ai suoi compagni martiri Seyyed Hassan #Nasrallah e Hajj Qassem #Soleimani”. @OsservatorioEsteri

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3616 · 11.11.2024 г., 11:56

For the first time, Israeli Prime Minister Benjamin Netanyahu admitted in a cabinet meeting on Sunday that he stands behind several terrorist attacks against Lebanon such as the assassination of Hezbollah chief and the pagers and walkie-talkies attacks. #Hezbollah#Nasrallah#Pagers#UnitedStates#Israel#Netanyahu

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3129 · 25.08.2024 г., 21:05

#Hezbollah Chief Sayyed Hassan #Nasrallah refuted Israeli claims about a preemptive strike ahead of “Operation Al-Arbaeen” in the #Israeli depth. He also set a condition of resuming the retaliation, which has to do with the enemy’s admitting of losses inflicted in first phase. #Lebanon#SouthLebanon#IsraeliArmy

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3247 · 19.09.2024 г., 18:41

In the first remarks after the Israeli terrorist attack against Lebanon, Hezbollah Secretary General Hassan Nasrallah termed the aggression as a declaration of war from the Israeli side. #Hezbollah#Lebanon#Nasrallah#Pagers#Israel#Mossad#Gaza#Palestine

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3122 · 25.08.2024 г., 13:46

Lebanese #Hezbollah military media releases video showing bases targeted in #Israel part of the First Phase of its response to the assassination of senior commander Fuad Shukr and killing of several civilians in #Beirut's southern suburbs on July 31. #Lebanon#SouthLebanon#Nasrallah#Gaza#Palestine#IsraeliArmy

12
ПретходнаСтраница 1 од 2Следна