Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. TreeView with custom type for delegate
Qt 6.11 is out! See what's new in the release blog

TreeView with custom type for delegate

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.3k Views 2 Watching
  • 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.
  • hvoigtH Offline
    hvoigtH Offline
    hvoigt
    wrote on last edited by
    #1

    Re: Add more than text to TreeView delegates? (like an extra Icon)

    I just found a nicer way to achieve passing multiple values from the model to the delegate. You can register a custom type with the QVariant by using Q_DECLARE_METATYPE:

    http://doc.qt.io/qt-5/qmetatype.html#Q_DECLARE_METATYPE

    You have to register that custom with qml:

    qmlRegisterType<CustomType>("hvoigt.net", 1, 0, "CustomType");
    

    You can then return a pointer of that custom type inside an QVariant from the data() method of the model. Now you can use that instance of the custom type inside the qml delegate as you would with any custom type.

    I have updated my TreeView example code with that:

    https://github.com/hvoigt/qt-qml-treeview/tree/master

    1 Reply Last reply
    0
    • hvoigtH Offline
      hvoigtH Offline
      hvoigt
      wrote on last edited by
      #2

      It seems the reference to the original question does not work:

      https://forum.qt.io/topic/67428/add-more-than-text-to-treeview-delegates-like-an-extra-icon

      And it seems you can not open a topic without marking it as a question? Or did I just not find the button for that?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by SGaist
        #3

        Hi,

        Double check the link, it seems there are ... in it that break the stuff.

        You should be able to change the type of thread you want to start when writing it or later on with the "Topic Tools" button

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

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