Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Modal Flickable List
Forum Updated to NodeBB v4.3 + New Features

Modal Flickable List

Scheduled Pinned Locked Moved QML and Qt Quick
13 Posts 4 Posters 6.4k 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.
  • A Offline
    A Offline
    anselmolsm
    wrote on last edited by
    #2

    Put a ListView (which inherits Flickable) inside an Item that appears only when this button is clicked. Something like this:

    @
    import Qt 4.7

    Item {
    width: 360
    height: 360

    //Button
    Rectangle {
        width: 50
        height: 50
        color: "red"
        MouseArea {
            anchors.fill:  parent
            onClicked: {
                list.visible = true;
            }
        }
    }
    
    // This List is a custom element
    List {
        id: list
        visible: false
        anchors.fill:  parent
    }
    

    }
    @

    Of course, it is just a pretty simple example. You have to add stuff to close the List element, etc.
    (Did I understand what you want to do?)

    Anselmo L. S. Melo (anselmolsm)

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kyleplattner
      wrote on last edited by
      #3

      Where do I add the items in my list?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        anselmolsm
        wrote on last edited by
        #4

        kyleplattner, for more details, check "this example":http://doc.qt.nokia.com/4.7/qml-listview.html#example-usage .

        Anselmo L. S. Melo (anselmolsm)

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kyleplattner
          wrote on last edited by
          #5

          I followed the example exactly and the text will not show up.

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

            Here is code I am using:

            @ Rectangle {
            id: rectangle2
            x: 155
            y: 117
            width: 248
            height: 336
            radius: 22
            border.width: 1
            smooth: true
            border.color: "#000000"
            gradient: Gradient {
            GradientStop {
            position: 0
            color: "#5e5e5e"
            }

                    GradientStop {
                        position: 1
                        color: "#444444"
                    }
                }
            
                ListView {
                    id: list_view1
                    x: 155
                    y: 117
                    width: 250
                    height: 338
                    model: ListModel {}
                        delegate: Text {
                            text: name + ": " + number
                        }
            
                }
            }@
            
            1 Reply Last reply
            0
            • B Offline
              B Offline
              baysmith
              wrote on last edited by
              #7

              Here is a complete example. Is something like this what you are looking for?

              @

              import Qt 4.7

              Item {
              width: 360
              height: 360

              Rectangle {
                  id: button
                  width: buttonText.width + 10
                  height: buttonText.height + 10
                  radius: 3
                  border.width: 1
                  smooth: true
                  border.color: "#000000"
                  gradient: Gradient {
                      GradientStop {
                          position: 0
                          color: "#5e5e5e"
                      }
                      GradientStop {
                          position: 1
                          color: "#444444"
                      }
                  }
                  Text {
                      x: 5
                      y: 5
                      id: buttonText
                      text: "Press here"
                      color: "#ffffff"
                  }
                  MouseArea {
                      anchors.fill:  parent
                      onClicked: {
                          list.visible = !list.visible
                      }
                  }
              }
              
              ListView {
                  id: list
                  visible: false
                  anchors.top:  button.bottom
                  anchors.bottom:  parent.bottom
                  anchors.right:  parent.right
                  anchors.left:  parent.left
                  model: ListModel {
                      ListElement {
                          name: "Bill Smith"
                          number: "555 3264"
                      }
                      ListElement {
                          name: "John Brown"
                          number: "555 8426"
                      }
                      ListElement {
                          name: "Sam Wise"
                          number: "555 0473"
                      }
                  }
                  delegate: Text {
                      text: name + ": " + number
                  }
              }
              

              }
              @

              Nokia Certified Qt Specialist.

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

                Great, that gets the list to show up but what about scrolling with a flick gesture?

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  baysmith
                  wrote on last edited by
                  #9

                  Sorry. Forgot to anchor the width. Updated. Try it now.

                  Nokia Certified Qt Specialist.

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kyleplattner
                    wrote on last edited by
                    #10

                    So I implemented a list with a highlight but how can I set it up so that my highlight moves with mouse clicks (screen taps)?

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      baysmith
                      wrote on last edited by
                      #11

                      I would add something like this to the ListView

                      @

                          highlight: Rectangle {
                              width: list.currentItem.width
                              color: "lightsteelblue"
                              radius: 5
                          }
                          focus: true
                          MouseArea {
                              anchors.fill: parent
                              onClicked: {
                                  list.currentIndex = list.indexAt(mouseX, mouseY)
                              }
                          }
                      

                      @

                      Nokia Certified Qt Specialist.

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        kyleplattner
                        wrote on last edited by
                        #12

                        Thanks so much, that does it.

                        1 Reply Last reply
                        0
                        • H Offline
                          H Offline
                          hyperborean72
                          wrote on last edited by
                          #13

                          Hello,
                          I have a problem with that snippet.
                          When I click on the list within its initial view, it performs fine: the highlight runs to the item currently clicked. But when I scroll that flickable ListView, and my visible area starts for instance with 'index=3' item, this line:

                          list.currentIndex = list.indexAt(mouseX, mouseY)

                          still seems to calculate currentIndex as index at initial view when the visible area starts with 'index=1' item.
                          So the larger list and the scrolling distance, the further the highlight from the actual item it should be below.

                          Did I misunderstand your idea?
                          Please help.

                          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