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 слични објави

Пребарај: #oilindustry

当前筛选 #oilindustry清除筛选
Venezuelanalysis

@venanalysis · Post #2035 · 21.07.2025 г., 19:36

📰 NEWS | Venezuela: Oil Industry Navigates Sanctions, Places 90 Percent of Exports to China The Venezuelan oil industry has managed to maintain production and export levels in the wake of renewed US sanctions. State oil company PDVSA is now selling 90% of its crude to China. However, the Maduro government continues to court foreign investment to boost the energy sector recovery. Follow the link for the full report: https://venezuelanalysis.com/news/venezuela-oil-industry-navigates-sanctions-places-90-percent-of-exports-to-china/ #Venezuela#OilIndustry#China#PDVSA

Venezuelanalysis

@venanalysis · Post #2238 · 10.01.2026 г., 23:18

📰 NEWS | Trump Administration Hosts Oil Executives, Insists on Sweeping Venezuelan Oil Concessions The Trump administration hosted global oil executives and reiterated its claims to exercise control over present and future Venezuelan oil sales. Washington has maintained its pressure to impose conditions on the acting government in Caracas, with naval forces seizing a fifth oil tanker on Friday. Follow the link to read our report: https://venezuelanalysis.com/news/trump-administration-hosts-oil-executives-insists-on-sweeping-venezuelan-oil-concessions/ #OilIndustry#TrumpAdministration#Chevron#Venezuela

Venezuelanalysis

@venanalysis · Post #1897 · 04.03.2025 г., 19:50

🚨NEWS | Venezuela: US Shrinks Chevron Wind-Down Period to 30 Days Following ‘Crazy Cubans’ Pressure The Trump administration ordered the oil giant to cease its activities in Venezuela by April 3. The ramped-up economic sanctions will immediately affect the country’s oil output and potentially trigger renewed inflation. 🔗 Read the full report here: https://venezuelanalysis.com/news/venezuela-us-shrinks-chevron-wind-down-period-to-30-days-following-crazy-cubans-pressure/ #Sanctions#Chevron#OilIndustry#Trump

Venezuelanalysis

@venanalysis · Post #2244 · 14.01.2026 г., 21:47

📰 NEWS | Chinese Supertankers Turn Back as US Moves Ahead to Extort Venezuelan Crude With Washington stepping up its naval blockade, two Chinese-flagged supertankers turned back when headed to load Venezuelan crude. Commodities traders Vitol and Trafigura have begun to move Venezuelan oil. Trump officials insist that the sales proceeds will be deposited in US accounts. Read our report: https://venezuelanalysis.com/news/chinese-supertankers-turn-back-as-us-moves-ahead-to-extort-venezuelan-crude/ #OilIndustry#Sanctions#China#TrumpAdministration

Venezuelanalysis

@venanalysis · Post #2237 · 10.01.2026 г., 17:33

📹 VIDEO | Trump’s Oil Heist in Venezuela Historian Steve Ellner and Venezuelanalysis' Ricardo Vaz joined Sharmini Peries on theAnalysis.News to gather a historical perspective on the Venezuelan oil industry and how US imperialist interests have played a role. Watch the video: https://venezuelanalysis.com/video/trumps-oil-heist-in-venezuela/ #Venezuela#OilIndustry#History#Trump

Venezuelanalysis

@venanalysis · Post #2245 · 16.01.2026 г., 03:27

📹 VIDEO | Trump–Rodríguez Oil Talks Test Venezuela’s Sovereignty Venezuelanalysis founder and contributing editor Gregory Wilpert joined Sharmini Peries on theAnalysis.News to discuss US claims over the Venezuelan oil industry and the broader context of the struggle for sovereignty. Follow the link to watch: https://venezuelanalysis.com/video/trump-rodriguez-oil-talks-test-venezuelas-sovereignty/ #OilIndustry#Venezuela#NationalSovereignty#History

Venezuelanalysis

@venanalysis · Post #1602 · 14.06.2024 г., 23:47

Over the past century, oil has played an outsized role in Venezuela. It is no wonder that the United States, in its neverending regime-change plots, chose to target this crucial sector with crushing sanctions. Our latest video examines the crude reality of coercive measures against the Venezuelan oil industry. #Venezuela#Sanctions#USPolicy#VenezuelanOil#OilIndustry https://youtu.be/lwcB4Z9jwGA