[Interest] Qt Quick UI Forms & item views: best practices

Ola Røer Thorsen ola at silentwings.no
Wed Jan 21 11:10:37 CET 2015


Den 2015-01-21 09:24, skrev Alexander Ivash:
> Yes, your are right, there was an error in my sample, but even fixing 
> it doesn't change a lot: ui.qml files becomes not editable via 
> QtCreator's QML designer due to presence
>
> onClicked: root.onClicked(root.model.get(index)); /// this line makes 
> QtCreator unhappy :(
>

As far as I have understood it, the whole idea of the ui.qml files are 
that they should not contain any javascript whatsoever. It's very 
difficult to develop a designer that understands what to do with 
javascript snippets while only working on a single file from a larger 
application.

You have to expose all items in your .ui.qml file via property aliases, 
and do all your logic code from the outside. The regular qtcreator 
designer doesn't have any button for exposing items as properties so you 
need to add them in the text editor manually. The commercial edition of 
qtcreator has such a button I think.

It's a bit confusing for new users. The default Quick project in 
QtCreator makes an example .ui.qml file with 3 buttons exposed as 
property aliases, and shows how to use them. It warns the user not to 
edit these ui.qml files by hand. Still, .ui.qml files are mostly useless 
if you don't create any property aliases, which you have to do by typing 
them into the text editor.

Maybe you could try something like this (haven't tested it myself):

Form.ui.qml
Item {
    property alias listView: theListView

    ListView {
       id: theListView
    }
}

Delegate.ui.qml
Item {
    property alias ma: mouseArea
    MouseArea {
       id: mouseArea
       anchors.fill: parent
   }
}

main.qml
Item {
    Form {
       listView.delegate: Delegate {
          ... javascript and bindings here.. .
       }
    }
}



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150121/e579ad13/attachment.html>


More information about the Interest mailing list