Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to use SwipeView and ListView together?
Forum Updated to NodeBB v4.3 + New Features

How to use SwipeView and ListView together?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Quang PhuQ Offline
    Quang PhuQ Offline
    Quang Phu
    wrote on last edited by Quang Phu
    #1

    Hi all,

    I want to use SwipeView and ListView together, it means, in a page, if I swipe left and right, it would change to previous or next page; otherwise, if I scroll up and down, the content in list view would scroll up and down too. Now I just can scroll up and down.
    I'm using Qt 14.0
    This is my implement code:

        SwipeView {
            id: swipeView
            anchors { top: header.bottom; bottom: parent.bottom; left: parent.left; right: parent.right }
            currentIndex: 0
    
            Repeater {
                id: repeater
                model: totalPage
                Loader {
                   sourceComponent: QuizzPage {
                    }
                    active: SwipeView.isCurrentItem
                    onLoaded: {
                        console.log("Done load"+ index);
                    }
                }
            }
        }
    

    Thank you

    1 Reply Last reply
    0
    • W Offline
      W Offline
      werto87
      wrote on last edited by werto87
      #2

      ListView inherits from Flickable and Flickable has flickableDirection. Try to use flickableDirection: Flickable.VerticalFlick in your ListView
      flickableDirection: Flickable.VerticalFlick is default in ListView

      1 Reply Last reply
      0
      • W Offline
        W Offline
        werto87
        wrote on last edited by werto87
        #3

        Try this example it uses a swipe view and ListView

        • tested on Android Mobile and Desktop

        import QtQuick 2.14
        import QtQuick.Controls 2.14
        import QtQuick.Layouts 1.14
        import QtQml.Models 2.14

        ApplicationWindow {
        id: root
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")

        SwipeView {
            anchors.fill: parent
            currentIndex: 1
            ListView {
                spacing: 5
                Layout.fillHeight: true
                Layout.fillWidth: true
                model: model
                delegate: Rectangle {
                    width: root.width
                    height: 75
                    color: "steelblue"
                }
            }
            ListView {
                spacing: 5
                Layout.fillHeight: true
                Layout.fillWidth: true
                model: model
                delegate: Rectangle {
                    width: root.width
                    height: 75
                    color: "red"
                }
            }
            ListView {
                spacing: 5
                Layout.fillHeight: true
                Layout.fillWidth: true
                model: model
                delegate: Rectangle {
                    width: root.width
                    height: 75
                    color: "yellow"
                }
            }
        }
        ListModel {
            //just a model with some elements
            id: model
            ListElement {}
            ListElement {}
            ListElement {}
            ListElement {}
            ListElement {}
            ListElement {}
            ListElement {}
            ListElement {}
            ListElement {}
            ListElement {}
            ListElement {}
            ListElement {}
        }
        

        }

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved