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

Резултати

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

Пребарај: #ailiteracy

当前筛选 #ailiteracy清除筛选
AI & Law

@ai_and_law · Post #694 · 04.11.2025 г., 08:04

🇳🇱Netherlands' DPA Iissues Guide on Building AI Literacy The Netherlands' data protection authority, Autoriteit Persoonsgegevens, published guidance on developing AI literacy. The AP said AI literacy is critical for developing and deploying responsible AI and algorithms. The guide contains information on legal obligations and offers practical examples for implementing the AP's AI action plan, which is updated periodically. #AILiteracy

Hashtags

AI & Law

@ai_and_law · Post #581 · 30.05.2025 г., 07:04

🇪🇺AI Literacy Is Now a Legal Requirement in the EU: How it Works? As of February 2, 2025, Article 4 of the EU AI Act is in force—and with it, a new legal obligation: AI literacy is no longer optional. Providers and deployers of AI systems must ensure that their personnel, and anyone handling AI systems on their behalf, have sufficient understanding of how these systems function, what risks they carry, and how they interact with the people affected by them. The European AI Office has just released detailed Q&A guidance to clarify what this means in practice. It addresses the definition of “AI literacy,” how to assess adequate knowledge levels based on staff education, experience, and use context, and how enforcement will be handled. This is a significant compliance shift—especially for companies deploying AI in sensitive sectors. Training and governance functions will now need to be legally auditable. #AIAct#AILiteracy#AICompliance#AIGovernance

AI & Law

@ai_and_law · Post #768 · 19.02.2026 г., 08:04

🇺🇸U.S. Department of Labor Launches Federal AI Literacy Framework The U.S. Department of Labor has introduced the United States’ first federal-level AI literacy framework, a voluntary initiative aimed at guiding AI literacy programs across government, the public workforce, and education systems. The framework defines AI literacy as a foundational set of competencies enabling responsible use and evaluation of AI technologies, with a primary focus on generative AI as a core workplace tool. It is intended as a baseline understanding rather than specialized training for AI developers. Designed for broad application, the framework encourages tailored programs for different roles and contexts. It outlines benefits for workers (independent skill-building and adaptation to AI-enabled environments), employers (responsible deployment and workforce transition), and education providers (curriculum design and competency assessment). Although nonbinding, it is expected to influence private-sector training initiatives in the U.S. and abroad. The document emphasizes that AI literacy requirements will evolve with technological change, labor market developments, and implementation feedback. #AIRegulation#AILiteracy#GenerativeAI#PublicPolicy

AI & Law

@ai_and_law · Post #795 · 30.03.2026 г., 07:04

🇺🇸U.S. Department of Labor Launches “Make America AI-Ready” Initiative The U.S. Department of Labor announced the “Make America AI-Ready” initiative, a free AI literacy course designed to provide workers with foundational AI skills. The program delivers training via text messages, allowing users to complete the course in seven days with daily 10-minute sessions, aiming to ensure accessibility, including for individuals without reliable internet or devices. Developed in partnership with education technology company Arist, the initiative aligns with the White House’s AI Action Plan and America’s Talent Strategy. The course covers five areas: understanding AI principles, exploring use cases, directing AI through prompts, evaluating outputs, and responsible use. According to officials, the program is intended to prepare workers for an AI-driven economy and expand access to AI-related skills and opportunities. #AIRegulation#AILiteracy#FutureOfWork#USpolicy#AIgovernance