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. ScrollView And ListModel Problem
Forum Updated to NodeBB v4.3 + New Features

ScrollView And ListModel Problem

Scheduled Pinned Locked Moved Mobile and Embedded
9 Posts 2 Posters 4.5k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    kingsta
    wrote on last edited by
    #1

    Hello guys

    I want to show ListElements on ScrollView. When I run the program, program is crushed. What is the problem?

    @import QtQuick 2.1
    import QtQuick.Controls 1.1

    ApplicationWindow {
    title: qsTr("Hello World")
    width: 640
    height: 480

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }
    
    ScrollView{
        width: parent.width
        height: parent.height
    
        flickableItem.interactive: true
    
        ListModel {
            id: fruitModel
    
            ListElement {
                name: "Apple"
                cost: 2.45
            }
            ListElement {
                name: "Orange"
                cost: 3.25
            }
            ListElement {
                name: "Banana"
                cost: 1.95
            }
    
            ListView {
                anchors.fill: parent
                model: fruitModel
                delegate: Row {
                    Text { text: "Fruit: " + name }
                    Text { text: "Cost: $" + cost }
                }
            }
        }
    }
    

    }
    @

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kingsta
      wrote on last edited by
      #2

      I think This topic should moves to Qt Quick Category. Please move that.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        First, your ListView is inside ListModel which cannot be, so you need to close breacket } before ListView and separate these two.

        Second, put ListModel before ScrollView because:
        "Only one Item can be a direct child of the ScrollView and the child is implicitly anchored to fill the scroll view."

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kingsta
          wrote on last edited by
          #4

          [quote author="Lepa Brena" date="1389089662"]First, your ListView is inside ListModel which cannot be, so you need to close breacket } before ListView and separate these two.

          Second, put ListModel before ScrollView because:
          "Only one Item can be a direct child of the ScrollView and the child is implicitly anchored to fill the scroll view."

          [/quote]
          You definitely right. I change code a little bit.

          SteelStandardListPage.qml
          @import QtQuick 2.1
          import QtQuick.Controls 1.1
          import QtQuick.Controls.Styles 1.1

          Item{

          ListModel{
              id:steelTypeModel
          
              ListElement{
                  profileType: "I Profile"
                  profileTypePage: "content/ProfileDetailPage.qml"
              }
          
              ListElement{
                  profileType: "U Profile"
                  profileTypePage: "content/ProfileDetailPage.qml"
              }
          }
          
          ScrollView {
              width: parent.width
              height: parent.height
          
              flickableItem.interactive: true
          
              ListView {
                  anchors.fill: parent
                  model: steelTypeModel
                  delegate: AndroidDelegate {
                      text: "Type: " + profileType
                      //onClicked: StackView.push({Item: "content/ProfileDetailPage.qml", immediate: true, replace: true})
                      onClicked: StackView.push(Qt.resolvedUrl(profileTypePage))
                  }
          

          style: ScrollViewStyle{
          transientScrollBars: true
          handle: Item{
          implicitWidth: 14
          implicitHeight: 26
          Rectangle{
          color: "#424246"
          anchors.fill: parent
          anchors.topMargin: 6
          anchors.leftMargin: 4
          anchors.rightMargin: 4
          anchors.bottomMargin: 6
          }
          }
          scrollBarBackground: Item{
          implicitWidth: 14
          implicitHeight: 26
          }

              }
          
          }@
          

          How can I use push to show another pages? For example; I touch the first List Element(I profile) then I want to show "content/ProfileDetailPage.qml" . I wrote a code, but this code doesn't work.

          @onClicked: StackView.push(Qt.resolvedUrl(profileTypePage))@

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            You should have StackView item first, so you can push another page on it.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kingsta
              wrote on last edited by
              #6

              [quote author="Lepa Brena" date="1390898659"]You should have StackView item first, so you can push another page on it.[/quote]

              So every qml file contain own StackView. For example; 1.qml file has StackView ( id:StackView1), 2.qml file has StackView ( id:StackView2). Am I right?

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                Hmmm... I think I didn't understand you well...
                StackView is a control like Image, ScrollView and so.. you have to create it in your .qml.

                Best example is "Touch" in QML examples...
                "Touch QML Example":http://qt-project.org/doc/qt-5.1/qtquickcontrols/touch-main-qml.html

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kingsta
                  wrote on last edited by
                  #8

                  [quote author="Lepa Brena" date="1390993003"]Hmmm... I think I didn't understand you well...
                  StackView is a control like Image, ScrollView and so.. you have to create it in your .qml.

                  Best example is "Touch" in QML examples...
                  "Touch QML Example":http://qt-project.org/doc/qt-5.1/qtquickcontrols/touch-main-qml.html[/quote]

                  Touch example contains one StackView. I wrote StackView every qml files and I can pass the pages as I want. Is there any problem on the future?

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    Sorry, did not see StackView item. Can you add some id, and the use it?
                    id: myStackView

                    onClicked: myStackView.push(Qt.resolvedUrl(profileTypePage))

                    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