[Interest] ListView not start at index 0 when is Horizontal
Federico Buti
bacarozzo at gmail.com
Mon Apr 6 18:28:26 CEST 2015
Hi Gianluca,
it's hard to say if it is a bug or not. The problem is anyway related to
the sizing of the list, i.e. if you set listHistory.width to
width: parent.width
the problem disappears. If you set a similar constraint for the height and
set the ListView to the vertical layout the same, odd, behaviour occurs.
Instead of using such constraints, what about using a layout to size your
three elements? Something involving a RowLayout, for instance, works
perfectly. See the modified code below:
import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Layouts 1.1
Window {
visible: true
width: 400
height: 400
RowLayout {
anchors.fill: parent
Item {
id: previous
Layout.preferredWidth: parent.width / 3
Layout.fillHeight: true
}
ListView {
id: listHistory
Layout.preferredWidth: parent.width / 3
Layout.fillHeight: true
clip: true
orientation: ListView.Horizontal
snapMode: ListView.SnapToItem
highlightRangeMode: ListView.StrictlyEnforceRange
onCurrentIndexChanged: console.log( "Current Index: "+currentIndex )
model: modelHistory
delegate: Item {
width: listHistory.width
height: listHistory.height
Text {
width: parent.width
anchors.bottom: parent.verticalCenter
font.pixelSize: 20 //* mm
minimumPixelSize: 10 //* mm
fontSizeMode: Text.Fit
horizontalAlignment: Text.AlignHCenter
text: year
}
Text {
width: parent.width
height: parent.height/2-1.5 //* mm
anchors.bottom: parent.bottom
font.pixelSize: 20 //* mm
minimumPixelSize: 10 //* mm
fontSizeMode: Text.Fit
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.Wrap
text: what
}
}
}
Item {
id: next
Layout.preferredWidth: parent.width / 3
Layout.fillHeight: true
}
}
}
Cheers,
F.
---
Federico Buti
On 6 April 2015 at 11:15, Gianluca <gmaxera at gmail.com> wrote:
> Dear all,
> I’m experiencing a unexpected behavior:
> I have a ListView in QML that display data from a ListModel.
> The dimension of ListView is set in such a way that only one element
> delegate is display at time.
> When I configure the ListView to be Vertical, then the first item
> displayed is the first item on the ListModel.
> But when I configure the ListView to be Horizontal, then the first item
> displayed is not the first item on the ListModel … but one in the middle.
> Why ??
> Forcing the property currentIndex to 0 do not solve the problem.
> Calling positionViewAtBeginning do not solve the problem :-(
>
> What else I can do ?
>
> // Code of ListView:
> ListView {
> id: listHistory
> anchors.centerIn: parent
> height: parent.height
> width: parent.width-previous.width-next.width
> clip: true
> orientation: ListView.Horizontal
> snapMode: ListView.SnapToItem
> highlightRangeMode: ListView.StrictlyEnforceRange
> onCurrentIndexChanged: console.log( "Current
> Index: "+currentIndex )
> model: modelHistory
> delegate: Item {
> width: listHistory.width
> height: listHistory.height
> Text {
> width: parent.width
> anchors.bottom:
> parent.verticalCenter
> color: "white"
> font.pixelSize: 8.5*mm
> minimumPixelSize: 4*mm
> fontSizeMode: Text.Fit
> horizontalAlignment:
> Text.AlignHCenter
> text: year
> }
> Text {
> color: "white"
> width: parent.width
> height: parent.height/2-1.5*mm
> anchors.bottom: parent.bottom
> font.pixelSize: 2.4*mm
> minimumPixelSize: 1*mm
> fontSizeMode: Text.Fit
> horizontalAlignment:
> Text.AlignHCenter
> wrapMode: Text.Wrap
> text: what
> }
> }
> }
>
> // On the console I get the following message:
> qml: Current Index: 0
> qml: Current Index: 19
>
> But Who change the current index to 19 ??
>
> Thanks,
> Gianluca.
>
>
> _______________________________________________
> 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/20150406/6ab69902/attachment.html>
More information about the Interest
mailing list