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

Резултати

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

Пребарај: #mozo

当前筛选 #mozo清除筛选
Mozo AI Hub

@mozo_news · Post #112 · 13.10.2024 г., 03:33

🚀Mozo hits 450K followers! 🎉 A massive thank you to our amazing community for your support! We’re just getting started—stay tuned for more exciting updates, events, and rewards. Let’s keep growing together! #Mozo Website|Twitter|Community|Telegram Mini App|News Channel

Hashtags

Mozo AI Hub

@mozo_news · Post #111 · 02.10.2024 г., 13:00

Have you noticed that #Mozo is trending? 😜 We’re thrilled to see our community growing and embracing the future of decentralized AI! Website|Twitter|Community|Telegram Mini App|News Channel

Hashtags

Mozo AI Hub

@mozo_news · Post #109 · 30.09.2024 г., 22:28

Data is more than just numbers—it's a reflection of who we are. The idea that corporations and governments can own or control our data threatens our personal freedom. It’s time to reclaim your data and take back control. #Mozo Website|Twitter|Community|Telegram Mini App|News Channel

Hashtags

Mozo AI Hub

@mozo_news · Post #106 · 14.09.2024 г., 01:33

GM #Mozo Builders🌞 Something exciting is just around the corner. Stay tuned for what’s coming next! 👀 Website|Twitter|Community|Telegram Mini App|News Channel

Hashtags

Mozo AI Hub

@mozo_news · Post #105 · 09.09.2024 г., 07:54

🚀 Exciting news! #Mozo is partnering with CocosStudio, the premier platform powered by the world’s No.1 mini-game engine, Cocos Engine! With a global community of over 1.6 million developers across 203 regions, Cocos Studio leads in mini-game development, incubation, and acceleration. Together, we’re bridging the gap between Web2 and Web3, empowering developers to seamlessly transition to the decentralized world. Website|Twitter|Community|Telegram Mini App|News Channel

Hashtags

Mozo AI Hub

@mozo_news · Post #97 · 13.08.2024 г., 04:04

We’re excited to announce our partnership with koi_protocol, a groundbreaking platform backed by Binance Labs K.O.I combines the joy of virtual pet care with sophisticated AI competitive elements, all anchored on the Ethereum blockchain. This immersive environment caters to both casual and competitive gamers, enabling them to nurture, train, and trade their virtual companions. Together, #Mozo and K.O.I will leverage advanced AI to enhance user experiences and drive innovation in the virtual pet gaming space. Website|Twitter|Community|Telegram Mini App|News Channel

Hashtags

Mozo AI Hub

@mozo_news · Post #96 · 12.08.2024 г., 00:25

GM #Mozo Builders from 🇺🇸🇮🇩🇰🇷🇻🇳🇳🇬🇮🇳🇹🇷🇹🇭🇨🇬🇧🇦🇷🇺🇧🇪🇳🇱🇱🇺🇪🇸🇵🇹🇮🇷🇸🇰🇷🇴🇬🇷🇯🇵🇧🇩🇫🇷🇸🇬🇩🇪🇮🇹🇵🇭 Website|Twitter|Community|Telegram Mini App|News Channel

Hashtags

Mozo AI Hub

@mozo_news · Post #79 · 15.07.2024 г., 16:13

How to drive mass adoption of Web3? Lower the entry barriers for users! It's that simple. 👑 Pepe King is coming! Join #Mozo now and use your Telegram to earn free points. Don’t miss out! 🎮Play Now: https://t.me/mozoai_bot/hub Website|Twitter|Community|Telegram Mini App|News Channel

Hashtags

Mozo AI Hub

@mozo_news · Post #61 · 30.06.2024 г., 04:06

1/6 The limitations of centralized control highlight the critical need for decentralized data in LLM development and RAG services. Let's explore why decentralized data is the future. 2/6 Enhanced Data Quality: Decentralization fosters a more inclusive environment where diverse user communities contribute data and perspectives. This enriches the knowledge base for LLMs, improving their performance and accuracy. 3/6 Reduced Biases: By removing centralized control of data sources, we significantly reduce potential biases. This promotes the development of fairer and more ethical AI models that benefit all users. 4/6 Increased Innovation: Decentralization fosters an environment where new ideas and contributions from the broader community can flourish, accelerating innovation in AI and leading to more advanced and powerful LLM models. 5/6 By harnessing the power of decentralized data, #Mozo proposes a novel solution that empowers regular users to actively contribute to the future of AI. This not only unlocks the full potential of LLMs but also fosters a more inclusive and ethically responsible AI development landscape. 6/6 Join us in revolutionizing AI development. Embrace decentralization and help create a more accurate, fair, and innovative future. Website|Twitter|Community|Telegram Mini App|News Channel

Hashtags

Mozo AI Hub

@mozo_news · Post #60 · 28.06.2024 г., 06:21

🔥 Exciting news! #Mozo 🌟 New features are now live on the Mozo platform! 🌟 ✅Our team is committed to continuous innovation to bring you a better experience. ❤️Explore these new features today and enjoy more efficient and smarter services!

Hashtags

Mozo AI Hub

@mozo_news · Post #51 · 22.06.2024 г., 15:05

Why #Mozo Matters: ✅Decentralized intelligence, empowering everyone. ✅Collaboration that enhances collective strength. ✅Innovation that revolutionizes industries and lives. Be a part of Mozo’s journey! Website|Twitter|Community|Telegram Mini App|News Channel

Hashtags

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