Important: Please read the Qt Code of Conduct -

PySide2 custom compound QML widget

  • I want to have a custom widget made of a rectangle and a text label to use as a "desktop icon". So far I've been able to build a basic one in a separate QML file and include it in another QML file. What I'd like is to have a custom QML widget that accepts parameters such as "iconFile" and "text". Then I want to generate a number of them based off of data, and add them to a GridLayout.

    Searching online I found an example of a custom QWidget here but that seems to be for QtWidgets, not QtQuick. But the idea is basically the same. (That example is PyQt5 but it worked verbatim in PySide2.)

    Maybe I'm thinking about it wrong? I'm new to this stack. But I was hoping there would be a way to create such things purely in QML, then create them, maybe in javascript, based on data passed by a signal from the python code. ... Or ... Define a class of the widget and do the same.


  • Moderators

    May I suggest a different approach,

    Instead of a GridLayout, use a GridView, that way you can simply use your DesktopIcon.qml as the views delegate and as a model you can pass it a list of iconFile & text pairs.

    Should work

  • Thank you @J-Hilk , that is exactly what I was looking for.

Log in to reply