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

Alexander Ivash elderorb at gmail.com
Wed Jan 21 11:28:27 CET 2015


Thank you for your reply, your approach is exactly what I meant in the
topic start: 'It seems for me like currently only ListView itself can be
defined inside the *.ui.qml file, and the delegate needs to be defined
inside the corresponding *.qml file'. Sure, it can be done in such a way,
but for me inability to propagate signals is a big limitation. Instead of
creating stand-alone reusable 'CustomListView' component I have to split it
into 'CustomListView' and 'CustomListViewDelegate' just to be able to edit
in the QML designer. I can understand why javascript functions are not
allowed, but signals are a bit different from my prospective. From the
other side if ListView would have 'itemClicked' signal out-of-box, this
would solve this particular case.

2015-01-21 13:10 GMT+03:00 Ola Røer Thorsen <ola at silentwings.no>:

>  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.. .
>       }
>    }
> }
>
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150121/a44707a0/attachment.html>


More information about the Interest mailing list