Solved TreeView with custom type for delegate
-
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 thedata()
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:
-
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?
-
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