[Interest] Can QML model specify a range including negative numbers? For example -180 to +180 ?
André Somers
andre at familiesomers.nl
Fri Nov 6 15:26:48 CET 2015
Op 6-11-2015 om 14:52 schreef Edward Sutton:
>
>> On Nov 6, 2015, at 3:53 AM, André Somers <andre at familiesomers.nl
>> <mailto:andre at familiesomers.nl>> wrote:
>>
>> Op 6-11-2015 om 10:10 schreef Curtis Mitch:
>>> You can use the columnForeground component [1] for this purpose:
>>> import QtQuick 2.3
>>> import QtQuick.Controls 1.2
>>> import QtQuick.Extras 1.2
>>> import QtQuick.Controls.Styles 1.2
>>> ApplicationWindow {
>>> visible: true
>>> width: 640
>>> height: 480
>>> title: qsTr("Hello World")
>>> Tumbler {
>>> id: tumbler
>>> anchors.centerIn: parent
>>> TumblerColumn {
>>> model: 90
>>> }
>>> TumblerColumn {
>>> model: 60
>>> }
>>> TumblerColumn {
>>> model: 60
>>> }
>>> TumblerColumn {
>>> model: ["N", "S"]
>>> }
>> I don't think I would keep the N/S (or E/W) option in a separate
>> column. Why not integrate that into the first column?
>
> Can you please elaborate? Do you mean create a model with 180 items
> ranging from "N 0" to "N 90” and "S 0" to "S 90”?
>
> Or 180 numbers and the delegate adds a “N” or “S” and subtracts 90
> when needed?
The latter. That allows you to just specify model: 180 as your model.
Then you let the delegate display a N or S and adjust the value to the
right range (for instance by shifting the range from 0-180 to -90-90 and
then displaying a negative value as S and positive value as N, removing
the minus itself.) I guess you'll need to specify 182 though, as you
probably want all of N 0, N 90, S 0 and S 90.
>
>> You can easily use a delegate to on the column to display negative
>> values as S or W depending on latitude or longitude. To stick to a
>> standard notation, you would have to put the N/S/E/W first in the
>> column, like S 17|33|08.
>>
>> Using a delegate can also solve your model problem the whole thread
>> started with. Just use a number again as the model, but only use the
>> positive range from 0 to 360. Then in your delegate simply adjust the
>> value from the model to the actual value you want to display.
>
> So a QML delegate can transform magic model numbers into real-world
> user display data? For example a number 0 into “Apple”?
Sure.
>
> I am not sure I understand what delegates are operating on. In the
> case of a TumblerColumn it would be the current index?
>
> http://doc.qt.io/qt-5/qml-qtqml-models-delegatemodel.html
>
Delegates gets a styleData attached property, which in turn contains an
index, column, value, current (bool) and displacement (distance from
current). That is what you can use to do your rendering.
See
http://doc.qt.io/qt-5/qml-qtquick-controls-styles-tumblerstyle.html#delegate-prop
Something like
TumblerColumn {
model: 182
delegate: Text {
property int degrees: styleData.value - 90
text: degrees <= 0 ? "S " + -1 * degrees : "N " + degrees - 1
opacity: 0.4 + Math.max(0, 1 - Math.abs(styleData.displacement)) *
0.6 //from example
}
}
should work I think. This should yield a column with items from S 90 to
S 0 followed by N 0 to N 90. Did not try it though.
André
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151106/d4a7c987/attachment.html>
More information about the Interest
mailing list