×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Sep 2011
    Location
    Lebanon
    Posts
    59

    ListView inside ListView

    Hi,
    I want to make an horizontal listView works as a delegate for another veritcal listView, I've wrote the following code:

    Code:
    import Qt 4.7
    
    Item {
        id:main
        width: 360
        height: 640
    
        Component{
            id:myDelegate
                ListView{
                    id:list2
                    spacing: 5
                    width:list.width
                    height:list.height/3
                    interactive: true
                    orientation: ListView.Horizontal
                    model: ListModel {
                        ListElement {
                            name: "Bill Smith"
                            number: "555 3264"
                        }
                        ListElement {
                            name: "John Brown"
                            number: "555 8426"
                        }
                        ListElement {
                            name: "Sam Wise"
                            number: "555 0473"
                        }
    
                        ListElement {
                            name: "Sam Wise"
                            number: "555 0473"
                        }
    
                        ListElement {
                            name: "Sam Wise"
                            number: "555 0473"
                        }
                    }
                    delegate: Text{text:name
                    width: main.width/3}
    
                    focus: true
                    MouseArea {
                        anchors.fill:  parent
                        onClicked: {
                            ListView.list2.currentIndex = ListView.list2.indexAt(mouseX, mouseY)
                        }
                    }
    
                }
        }
    
        ListView {
            id: list
            clip: true
            spacing: 5
            anchors.fill: parent
            orientation: ListView.Vertical
            model: Model{}
            delegate:myDelegate
    
    //        highlight: Rectangle {
    //            width: list.currentItem.width
    //            color: "lightsteelblue"
    //            radius: 5
    //        }
            focus: true
            MouseArea {
                anchors.fill:  parent
                onClicked: {
                    list.currentIndex = list.indexAt(mouseX, mouseY)
                }
            }
        }
    }
    The vertical listview scroll well but the horizontal one does not scroll,
    Any help?
    Thanks

  2. #2
    Registered User
    Join Date
    Sep 2011
    Location
    Moscow, Russian Federation
    Posts
    19

    Re: ListView inside ListView

    Horizontal swipe works only when horizontal list's width equals to screen one. The following code works as you expected:

    Code:
    import QtQuick 1.0
    
    Rectangle {
        id:main
        width: 360
        height: 640
    
        Component{
            id:myDelegate
                ListView{
                    id:list2
                    spacing: 5
                    width:main.width
                    height:main.height / 4
                    interactive: true
                    orientation: ListView.Horizontal
                    model: ListModel {
                        ListElement {
                            name: "Bill Smith"
                            number: "555 3264"
                        }
                        ListElement {
                            name: "John Brown"
                            number: "555 8426"
                        }
                        ListElement {
                            name: "Sam Wise"
                            number: "555 0473"
                        }
    
                        ListElement {
                            name: "Sam Wise"
                            number: "555 0473"
                        }
    
                        ListElement {
                            name: "Sam Wise"
                            number: "555 0473"
                        }
                    }
                    delegate: Text{text:name
                    width: main.width/3}
    
                    focus: true
                    MouseArea {
                        anchors.fill:  parent
                        onClicked: {
                            ListView.list2.currentIndex = ListView.list2.indexAt(mouseX, mouseY)
                        }
                    }
    
                }
        }
    
        ListView {
            id: list
            clip: true
            spacing: 5
            anchors.fill: parent
            orientation: ListView.Vertical
            model: 4
            delegate:myDelegate
    
    //        highlight: Rectangle {
    //            width: list.currentItem.width
    //            color: "lightsteelblue"
    //            radius: 5
    //        }
            focus: true
    /*        MouseArea {
                anchors.fill:  parent
                onClicked: {
                    list.currentIndex = list.indexAt(mouseX, mouseY)
                }
            }*/
        }
    }

  3. #3
    Registered User
    Join Date
    Sep 2011
    Location
    Lebanon
    Posts
    59

    Re: ListView inside ListView

    That is right
    Another solution was to remove the focus:true from the vertical list
    Thanks furj

Similar Threads

  1. QML ListView grows up
    By missdeer in forum [Archived] Qt Quick
    Replies: 6
    Last Post: 2011-11-23, 08:21
  2. ListView in QML
    By Siddharth5 in forum [Archived] Qt Quick
    Replies: 1
    Last Post: 2011-10-15, 15:19
  3. listview with checkbox
    By csy19861111 in forum [Archived] Qt General ( Qt技术)
    Replies: 2
    Last Post: 2011-06-15, 02:18
  4. Customize Listview in Qt
    By shank_19 in forum Qt
    Replies: 2
    Last Post: 2010-10-14, 03:08
  5. qt listview problems
    By kasperc in forum Nokia N9
    Replies: 2
    Last Post: 2010-04-28, 21:02

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×