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

Резултати

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

Пребарај: #beginners

当前筛选 #beginners清除筛选
Repositorio data science

@repo_science · Post #3297 · 12.06.2023 г., 18:53

#JavaScript#Beginners 🧰 JavaScript for Beginners The JavaScript for Beginners course aims to teach students who are new to JavaScript the fundamentals of the programming language. The course is taught by Darragh O’Neill a Udemy Instructor who has has received excellent reviews on the platform and has at present a 4.7 star rating. The course also contains several mini-projects and challenges so we can apply the JavaScript syntax that we have learnt. The course has overs 13+ hours of content and by the end of this course students will be familiar with all the fundamental aspects of the JavaScript language including data types, variables, let, const var, arrays, objects, functions, manipulating the DOM and more. 🔗Link ----- Canal principal:@repo_science Cupones: @freecoupons_reposcience -----

Repositorio data science

@repo_science · Post #4069 · 17.03.2024 г., 20:03

#Python#Excel#beginners 💻 Python in Excel 🗣 Scott Simpson ⏰30m Get a high-level overview of the Python in Excel features launched in the public beta preview. ----- Main channel: @repo_science Coupons: @freecoupons_reposcience -----

bjjfanaticsinstructionals

@bjjfanaticsinstructionals · Post #1815 · 18.05.2025 г., 14:35

😁Blue Print To Beginner: Intermediate Leglocks By Tom DeBlass😁 ➡️Attack The Lower Body With Highly Effective Submission Locks, Taught By One Of Grappling’s Most In-Demand Instructors - Tom DeBlass ➡️Tom DeBlass is a Renzo Gracie black belt who has spent years training with, learning from, and training some of the best grapplers and instructors in all of Brazilian jiu-jitsu - including Gordon Ryan, Garry Tonon, and more ➡️Set up your attacks from common grappling positions like the butterfly guard, closed guard, half guard, and more as Tom shares how to learn faster and cut through the mistakes easier $127😍$11.99😍 ❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️ 📱Payment: 📱📱📱 💰Submeta FOR FREE 🌈UFC Picks 👑MasterClass ✈️@bjjfanaticsinstructionals #TomDeblass#Leglocks#Beginners#NoGi 💁‍♀️Buy 💁‍♀️

GitHub Trends

@githubtrending · Post #14809 · 08.06.2025 г., 13:30

#ruby#beginners#hacktoberfest#hacktoberfest2020#helm#kubernetes#kubetools Kubernetes is a powerful tool for managing containerized applications. To learn Kubernetes, you can use platforms like Kubelabs, which offer interactive tutorials and labs. These resources help you understand Kubernetes concepts from the basics to advanced levels. By using these platforms, you can practice deploying applications, managing resources, and ensuring high availability and scalability. This hands-on approach helps you gain practical experience and improve your skills in managing complex applications efficiently. https://github.com/collabnix/kubelabs

Repositorio data science

@repo_science · Post #3180 · 12.05.2023 г., 19:53

#webScraping#Python#Scrapy 🐍 Scrapy course - Python web scraping for beginners The Scrapy #Beginners Course will teach you everything you need to learn to start scraping websites at scale using #Python Scrapy. Topics - Creating your first #Scrapy spider - #Crawling through websites & scraping data from each page - Cleaning data with Items & Item Pipelines - Saving data to CSV files, #MySQL & #Postgres#databases - Using fake #user-agents & headers to avoid getting blocked - Using #proxies to scale up your web scraping without getting banned - Deploying your #scraper to the cloud & scheduling it to run periodically 🗣️ Joe Kearney. 🔗Link 📢#youtube ⭐️ Resources ⭐️ Course Resources - Scrapy Docs - Course Guide - Course Github - The Python Scrapy Playbook ----- Main channel: @repo_science Coupons: @freecoupons_reposcience -----