<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to put Delegates at work in *.ui.qml files?]]></title><description><![CDATA[<p dir="auto">So far, I managed to work on data selected from a ListView like that:</p>
<pre><code>    //file: myList.qml
     ListView {
            ...
            delegate:  Item {
                ...
                MouseArea {
                    id: mouseArea

                    onClicked : doSomething(model.index, model.someData...)
            }
     }
</code></pre>
<p dir="auto">Now I want to split <em>mylist.qml</em> file in a <em>myList.qml + myListForm.ui.qml</em> pair.<br />
The problem I am facing is that the UI designer does not support function calls (doSomething), nor a can put the delegate in a property of <em>MyListForm.ui.qml</em> with a signal to be used by <em>MyList.qml</em>  (the delegate does not even appear in the UI navigator panel).</p>
<p dir="auto">Am I trying to do it the wrong way? What is the proper way to handle delegate actions in UI files?</p>
]]></description><link>https://forum.qt.io/topic/145982/how-to-put-delegates-at-work-in-ui-qml-files</link><generator>RSS for Node</generator><lastBuildDate>Fri, 06 Nov 2026 13:06:43 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/145982.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 25 Jun 2023 10:33:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to put Delegates at work in *.ui.qml files? on Mon, 26 Jun 2023 13:16:43 GMT]]></title><description><![CDATA[<p dir="auto">This is  the (admittedly messy) solution I've got so far.<br />
As I was unable to send a signal from UI file (altough QtQuick Designer accepts its declaration), I resorted to a variable registering the index of last clicked item:</p>
<pre><code>// file: SettingsPageForm.ui.qml
Item {

    property int clickIndex: -1
    // ....

    ListView {
        // ...
        model: dbSettingsModel

        delegate:  Item {
            // UI graphics stuff with model.name, model,value etc...
            // ...
            // the delegate sets the index, the handler will reset it to -1
            MouseArea { onClicked: clickIndex = model.index }
        }
    }


}

</code></pre>
<p dir="auto">The implementation logic watches for the change signal:</p>
<pre><code>// file: settingsPage.qml
SettingsPageForm {

    ...

    function launchEditor( index )
    {
        // getRole( row, roleName) was added to C++ model because 
        // model properties are available inside the delegate only
        editor.title =    dbSettingsModel.getRole( index, "name"     )
        editor.value =    dbSettingsModel.getRole( index, "value"    )
        editor.unit =     dbSettingsModel.getRole( index, "unit"     )
        editor.minValue = dbSettingsModel.getRole( index, "minValue" )
        editor.maxValue = dbSettingsModel.getRole( index, "maxValue" )
        editor.open()
    }

    onClickIndexChanged:  {
        if ( clickIndex &gt;= 0 )
            launchEditor( clickIndex )
        clickIndex = -1
    }
}

</code></pre>
<p dir="auto">I found no other way but to expand the C++ model (dbSettingsModel) with getRole( index, roleName), as model properties are not available outside delegates.<br />
Overall it works, but I feel I'm overcomplicating it, I fell there must be a much cleaner way taking advantage of delegates straight inside UI deisgner.</p>
]]></description><link>https://forum.qt.io/post/762646</link><guid isPermaLink="true">https://forum.qt.io/post/762646</guid><dc:creator><![CDATA[ellipse]]></dc:creator><pubDate>Mon, 26 Jun 2023 13:16:43 GMT</pubDate></item></channel></rss>