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. Listview first element always visible
Qt 6.11 is out! See what's new in the release blog

Listview first element always visible

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 5.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.
  • R Offline
    R Offline
    ReshmaS
    wrote on last edited by
    #1

    I created a listview and gave the width and height of the listview as 100 and 150. BUt I notice tat the first element of the listview goes beyond tat boundary and it is still visible.

    For ex. kindly chk this code in ur qt,

    // import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
    @import QtQuick 1.1

    Rectangle {
    width: 400
    height: 500

    ListView {
        id: list_view1
        x: 82
        y: 82
        width: 110
        height: 100
        delegate: Item {
            x: 5
            height: 40
            Row {
                id: row1
                spacing: 10
                Rectangle {
                    width: 40
                    height: 40
                    color: colorCode
                }
    
                Text {
                    text: name
                    anchors.verticalCenter: parent.verticalCenter
                    font.bold: true
                }
            }
        }
        model: ListModel {
            ListElement {
                name: "Grey"
                colorCode: "grey"
            }
    
            ListElement {
                name: "Red"
                colorCode: "red"
            }
    
            ListElement {
                name: "Blue"
                colorCode: "blue"
            }
    
            ListElement {
                name: "Green"
                colorCode: "green"
            }
        }
    }
    

    }@

    // Thanks in advance!

    Reshma

    1 Reply Last reply
    0
    • F Offline
      F Offline
      favoritas37
      wrote on last edited by
      #2

      Fortunately the solution to your problem is quite simple.

      Just add in your ListView the property clip set to true
      @
      ...
      ListView {
      id: list_view1
      clip:true
      ....
      }
      ...
      @

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ReshmaS
        wrote on last edited by
        #3

        Unfortunatley, that does not work for my program. Clip:true also clips the other area around the lIstview. I have 15 items and onclikc on every item gives a rectangle beside it. so when i set clip:true tat rectangle is also cut:(

        Reshma

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

          The ListView stores a buffer above and below the visible display area to improve performance. Delegates are instantiated and killed as they enter and leave the buffered area. You could set the buffer cache of the listView: http://doc.qt.digia.com/qt/qml-listview.html#cacheBuffer-prop

          However, you will likely see a ui performance hit, and get laggy transitions as you scroll through the list. I would recommend restructuring your elements in such a way that you maintain the listview buffer, but clip the area you want to display. For example, you could contain the ListView in an Item set to the ListViews height, but set to the width of the popup elements shown when you click an element, and clip to that item.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            ReshmaS
            wrote on last edited by
            #5

            *For example, you could contain the ListView in an Item set to the ListViews height, but set to the width of the popup elements shown when you click an element, and clip to that item.
            *
            I did not understand this statement.

            You want me to enclose Listmodel in an Item and then what should I do. Could you this in a small code.

            Reshma

            1 Reply Last reply
            0
            • R Offline
              R Offline
              ReshmaS
              wrote on last edited by
              #6

              @

              Item
              {
                  width:1000
                  height:300
              
              ListView{
                  id:lvmain
                  model:listModel
                  x:0
                 //clip:true
                  anchors{
                      left:parent.left
                      leftMargin:2
                      right:parent.right
                      rightMargin:2
              
                  }
                  clip:true
                  y:0
                  width: 150;
                  height: 300
                  delegate:  mainDelegate
                  section.property: "Group"
                  cacheBuffer: 0
                      section.criteria: ViewSection.FullString
                  section.delegate: sectionHeading
              }
              

              }@

              I tried smoething like this but i cannot see the onclik area beyond my clipped region.

              Reshma

              1 Reply Last reply
              0
              • A Offline
                A Offline
                admiralfluff
                wrote on last edited by
                #7

                If you use the chacheBuffer, you won't need to set clip:true.

                I was suggesting the following:

                @ Item
                {
                width:150+popupWidth
                height:300
                clip:true
                anchors{
                left:parent.left
                leftMargin:2
                right:parent.right
                rightMargin:2
                }
                ListView{
                id:lvmain
                model:listModel
                x:0
                y:0
                width: 150;
                height: 300
                delegate: mainDelegate
                section.property: "Group"
                section.criteria: ViewSection.FullString
                section.delegate: sectionHeading
                }
                }@

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  ReshmaS
                  wrote on last edited by
                  #8

                  NO this also does not work. I am unable to see that area beyond the width

                  Reshma

                  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