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

Резултати

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

Пребарај: #opensource

当前筛选 #opensource清除筛选
Linuxgram 🐧

@linuxgram · Post #18798 · 14.05.2026 г., 22:05

📰 BleachBit’s new TUI lets you clean without a desktop environment Open-source cleaning tool BleachBit has gained a text-based user interface (TUI) as an optional alternative to its standard graphical frontend. Unlike BleachBit’s existing CLI, which is intended for non-interactive use in scripts, the TUI is fully interactive, you navigate the interface with your keyboard (there’s limited mouse support) to select, preview and clean out cruft. 🔗 Source: https://www.omgubuntu.co.uk/2026/05/bleachbit-tui #opensource

Hashtags

Linuxgram 🐧

@linuxgram · Post #18795 · 14.05.2026 г., 19:31

📰 MuseScore Studio 4.7 Notation App Adds New Guitar Features MuseScore Studio 4.7 open-source notation app adds new engraving tools, guitar notation features, playback improvements, MP4 export, and more. 🔗 Source: https://linuxiac.com/musescore-studio-4-7-notation-app-adds-new-guitar-features/ #opensource

Hashtags

Linuxgram 🐧

@linuxgram · Post #18740 · 11.05.2026 г., 08:32

📰 Dusk is a reverse-engineered reimplementation of The Legend of Zelda: Twilight Princess The Legend of Zelda: Twilight Princess comes to PC thanks to a new open source reverse-engineered reimplementation called Dusk.Read the full article on GamingOnLinux. 🔗 Source: https://www.gamingonlinux.com/2026/05/dusk-is-a-reverse-engineered-reimplementation-of-the-legend-of-zelda-twilight-princess #opensource

Hashtags

Linuxgram 🐧

@linuxgram · Post #18739 · 11.05.2026 г., 08:06

📰 Restriced by the West, Huawei's Open Source HarmonyOS Now Powers 55 Million Devices It seems that Huawei has managed to create an ecosystem of hardware as well as software. 🔗 Source: https://feed.itsfoss.com/link/24361/17338103/harmony-os-rises-china #opensource

Hashtags

Linuxgram 🐧

@linuxgram · Post #18738 · 11.05.2026 г., 06:37

📰 Audacious 4.6 Media Player Promises File Browser Plugin, Beta Out Now Audacious 4.6 open-source media player is now available for public beta testing with a File Browser plugin, a macOS Now Playing plugin, support for playing Musepack SV8 files, and much more. 🔗 Source: https://9to5linux.com/audacious-4-6-media-player-promises-file-browser-plugin-beta-out-now #opensource

Hashtags

Linuxgram 🐧

@linuxgram · Post #18713 · 08.05.2026 г., 16:32

📰 Nintendo 64 emulator gopher64 adds controller hotkeys and auto-reconnect The free and open source Nintendo 64 emulator gopher64 has another useful new release out now, bringing a few more features to make it easier.Read the full article on GamingOnLinux. 🔗 Source: https://www.gamingonlinux.com/2026/05/nintendo-64-emulator-gopher64-adds-controller-hotkeys-and-auto-reconnect/ #opensource

Hashtags

Linuxgram 🐧

@linuxgram · Post #18695 · 07.05.2026 г., 07:22

📰vm2 Node.js Library Vulnerabilities Enable Sandbox Escape and Arbitrary Code Execution A dozen critical security vulnerabilities have been disclosed in the vm2 Node.js library that could be exploited by bad actors to break out of the sandbox and execute arbitrary code on susceptible systems.vm2 is an open-source library used to run untrusted JavaScript code inside a secure sandbox by intercepting and proxying JavaScript objects to prevent sandboxed code from accessing the host. 🔗 Source: https://thehackernews.com/2026/05/vm2-nodejs-library-vulnerabilities.html #opensource

Hashtags

Linuxgram 🐧

@linuxgram · Post #18693 · 06.05.2026 г., 20:34

📰Mesa 26.1 Released With Many Improvements For Open-Source Vulkan Drivers Eric Engestrom just announced another timely feature release of the Mesa drivers. Mesa 26.1 is out today for this collection of predominantly OpenGL and Vulkan drivers for a variety of hardware as well as the likes of Rusticl for OpenCL, Zink for OpenGL-on-Vulkan, various Windows acceleration components, and more... 🔗 Source: https://www.phoronix.com/news/Mesa-26.1-Released #opensource

Hashtags

Linuxgram 🐧

@linuxgram · Post #18692 · 06.05.2026 г., 17:58

📰 Inkscape 1.4.4 SVG Editor Released with a New Palette, Performance Improvements Inkscape 1.4.4 open-source SVG (Scalable Vector Graphics) editor is now available for download with a new palette, performance improvements,and bug fixes. Here’s what’s new! 🔗 Source: https://9to5linux.com/inkscape-1-4-4-svg-editor-released-with-a-new-palette-performance-improvements #opensource

Hashtags

Linuxgram 🐧

@linuxgram · Post #18674 · 05.05.2026 г., 03:41

📰 gThumb is barely recognisable in its GTK4/libadwaita port gThumb, the open-source image viewer and organiser, has been rewritten in Vala and ported to GTK4/libadwaita – and compared to the old UI, it’s barely recognisable. An alpha build of gThumb 4.0 is available for testing. Alongside the visual revamp, this brings support for WEBP and PNG animations, lets you export images in the JXL format and includes a censor filter to pixelate or blur out parts of an image. 🔗 Source: https://www.omgubuntu.co.uk/2026/05/gthumb-gtk4-port-redesign #opensource

Hashtags

Linuxgram 🐧

@linuxgram · Post #18669 · 04.05.2026 г., 17:17

📰 I tried an open-source Figma alternative, and its AI does what Figma's can't Not a Figma killer, but something more interesting. 🔗 Source: https://www.xda-developers.com/ditched-figma-for-open-source-tool-ai-does-what-figma-cant/ #opensource

Hashtags

Linuxgram 🐧

@linuxgram · Post #18663 · 03.05.2026 г., 22:06

📰 ReactOS Introduces Unified Live/Install Media, New Storage Driver ReactOS as the "open-source Windows" operating system project striving for binary compatibility with Microsoft Windows has seen some exciting improvements this week... 🔗 Source: https://www.phoronix.com/news/ReactOS-Unified-ISO #opensource

Hashtags

123•••10•••20•••30•••3738
ПретходнаСтраница 1 од 38Следна