@mygovcoronanewsdesk · Post #11493 · 01.12.2022 г., 07:54
India's G20 Presidency will work towards benefitting humanity as a whole. As the Hon PM Narendra Modi says, "WE CAN!" #G20India
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
Пребарај: #g20india
@mygovcoronanewsdesk · Post #11493 · 01.12.2022 г., 07:54
India's G20 Presidency will work towards benefitting humanity as a whole. As the Hon PM Narendra Modi says, "WE CAN!" #G20India
Hashtags
@MyGovCoronaNewsdesk · Post #12837 · 13.09.2023 г., 08:44
PM Narendra Modi is taking on the role of a Global Unifier. He's uniting nations for the global good, fostering collaboration on a worldwide scale. #G20#G20India
@MyGovHindi · Post #6850 · 13.09.2023 г., 08:45
दुनिया के नेताओं को एक मंच पर लाने एवं एकजुट करने की सराहनीय भूमिका निभा रहे पीएम नरेन्द्र मोदी वह वैश्विक भलाई के लिए देशों को एकजुट कर, विश्वव्यापी स्तर पर सहयोग को बढ़ावा दे रहे है। #G20#G20India
@mygovcoronanewsdesk · Post #11492 · 01.12.2022 г., 06:28
गौरवमयी पल 🇮🇳 आज से भारत प्रतिष्ठित एवं महत्वपूर्ण #G20 समूह की अध्यक्षता आधिकारिक तौर पर ग्रहण करेगा। आइए 'वसुधैव कुटुम्बकम' के मंत्र के साथ पूरी दुनिया को एक साथ लेकर आगे बढ़ने का संकल्प लें। #G20India https://youtu.be/VuQLi0_34vw
@mygovcoronanewsdesk · Post #11990 · 08.02.2023 г., 15:46
Come, Explore India's Digital Transformation Journey alongside the 1st DEWG Meeting and experience the Progress of Technology & latest innovations. 📍Lucknow 🗓13-15 Feb 🕑 2 PM onwards #G20DEWG#G20India
@mygovcoronanewsdesk · Post #11814 · 19.01.2023 г., 11:22
📣 Announcing! 1st Digital Economy Working Group Meeting taking place in Lucknow from February 13-15, 2023. #G20IndiaDEWG#G20India
Hashtags
@mygovcoronanewsdesk · Post #11494 · 01.12.2022 г., 10:34
India: the mother of democracy moving forward with a united voice and #JanBhagidari #G20India#NewIndia
Hashtags
@mygovcoronanewsdesk · Post #12033 · 12.02.2023 г., 11:57
"G20-DIA bringing Hon'ble PM Narendra Modi's dream to life" Be part of G20 #DigitalInnovationAlliance. Know more & Apply at: meitystartuphub.in/g20-dia/ #G20India#G20DEWG
@mygovcoronanewsdesk · Post #12321 · 13.03.2023 г., 05:19
Are you interested in creating digital innovations for the upliftment of societies? Participate in G20 #DigitalInnovationAlliance Visit: https://mygov.in/task/launch-applications-g20-digital-innovation-alliance/ #G20DIA#G20India
@mygovcoronanewsdesk · Post #11970 · 06.02.2023 г., 08:06
Calling startups in the field of #agritech & other sectors, developing digital solutions that can reduce the digital divide and boost the global economy for G20 #DigitalInnovationAlliance. Know more at https://mygov.in/task/launch-applications-g20-digital-innovation-alliance/ #G20India
@mygovcoronanewsdesk · Post #11991 · 09.02.2023 г., 06:26
The Digital Experience Centre & Digital India Exhibition scheduled alongside the 1st Meeting of #G20DEWG in Lucknow will be a learning opportunity for all #DigitalNagriks. See you there! #G20India
Hashtags