Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PySide2 custom compound QML widget
Forum Updated to NodeBB v4.3 + New Features

PySide2 custom compound QML widget

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 542 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    christofer
    wrote on last edited by
    #1

    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.

    Regards,
    chris

    J.HilkJ 1 Reply Last reply
    0
    • C christofer

      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.

      Regards,
      chris

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @christofer
      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
      https://doc.qt.io/qt-5/qml-qtquick-gridview.html


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • C Offline
        C Offline
        christofer
        wrote on last edited by
        #3

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

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved