Hmmm, that makes some sense. I presume the ListElement needs data that
is really constant, and Qt.* constants seem to be "script properties",
which may not be constant from the point of view of the qml engine.

Maybe you could resort to some kind of hack, like putting a table of
your Key constants in a javascript array or object. Granted, with this
hack, you would actually be constructing a parallel JS model to the
QML model.

Something along the lines of:
==============
Rectangle {
        width: 360
        height: 360

        function keys(c) {
                var table = {key7: Qt.Key_7}
                return table[c];
        }

        Repeater {
         model: ListModel {
                 ListElement { label: "7"; value: "7"; key: "key7" }
         }
         delegate: Text {
                 text: model.label + " : " + keys(model.key)
         }
        }
}
============

Could probably be improved for better semantics. You could use a JS
array instead of an object. But there may be some nice stuff to get
from the object, like the ability to access the data with dot notation
(ie: table.key7)

On Tue, Jan 4, 2011 at 7:43 PM, Alexey <ka...@mail.ru> wrote:
> I tried to create a numeric keyboard and stuck at the following: I want to 
> let every
> button handle its own key, so I pass this key through the model:
>
> Repeater {
>  model: ListModel {
>    id: model
>    ListElement { label: "7"; value: "7"; key: Qt.Key_7 }
>    ...
>
> In the button component (delegate) I use this:
>
> Keys.onPressed: {
>  if (event.key == model.key) {
>    event.accepted = true;
>    clicked(model.value);
>    ...
>
> But the point is that it doesn't let me use Qt.Key* constants:
> file:///D:/Projects/qmlinterface/Controls/Numpad.qml:25:43: ListElement: 
> cannot use script
> for property value
> ListElement { label: "7"; value: "7"; key: Qt.Key_7 }
>                                      ^
>
> I could hardcode key codes as integers, but it's not really portable... What 
> would you
> suggest, guys?
> _______________________________________________
> Qt-qml mailing list
> Qt-qml@qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>
_______________________________________________
Qt-qml mailing list
Qt-qml@qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

Reply via email to