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. [SOLVED] ListView painting outside of parent on scroll.
QtWS25 Last Chance

[SOLVED] ListView painting outside of parent on scroll.

Scheduled Pinned Locked Moved QML and Qt Quick
listviewscrolling
4 Posts 2 Posters 3.0k 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.
  • G Offline
    G Offline
    grheard
    wrote on last edited by grheard
    #1

    I have a listview with a Text delegate. When the view initially loads it paints inside the parent rectangle's boundary just fine. However, when I scroll the listview it paints outside the original boundaries. How can I keep this from happening?

    Scrrenshot

    Rectangle {
        id: indexView
        width: 100
        height: 300
        color: "transparent"
        border.color: parent.border.color
        border.width: 1
        radius: 10
    
        // Make the right border adjustable
        MouseArea {
            id: mouseAreaRightBorder
    
            property int oldMouseX
    
            anchors.right: parent.right
            anchors.top: parent.top
            anchors.bottom: parent.bottom
            width: 20
    
            onPressed: {
                oldMouseX = mouseX
            }
    
            onPositionChanged: {
                if (pressed) {
                    indexView.width = indexView.width + (mouseX - oldMouseX)
                }
            }
        }
    
        ListView {
            id: listView
            anchors.fill: parent
            anchors.margins: 5
            highlightFollowsCurrentItem: true
            currentIndex: -1
    
            model: cppIndex
            delegate: Text {
                text: modelData
                color: "white"
                width: listView.width
                clip: true
    
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        listView.currentIndex = index
                        listView.forceActiveFocus()
                    }
                }
            }
    
            highlight: Rectangle {
                color: "gray"
                opacity: 0.5
                border.color: indexView.border.color
                radius: 5
            }
        }
    }
    
    p3c0P 1 Reply Last reply
    0
    • G grheard

      I have a listview with a Text delegate. When the view initially loads it paints inside the parent rectangle's boundary just fine. However, when I scroll the listview it paints outside the original boundaries. How can I keep this from happening?

      Scrrenshot

      Rectangle {
          id: indexView
          width: 100
          height: 300
          color: "transparent"
          border.color: parent.border.color
          border.width: 1
          radius: 10
      
          // Make the right border adjustable
          MouseArea {
              id: mouseAreaRightBorder
      
              property int oldMouseX
      
              anchors.right: parent.right
              anchors.top: parent.top
              anchors.bottom: parent.bottom
              width: 20
      
              onPressed: {
                  oldMouseX = mouseX
              }
      
              onPositionChanged: {
                  if (pressed) {
                      indexView.width = indexView.width + (mouseX - oldMouseX)
                  }
              }
          }
      
          ListView {
              id: listView
              anchors.fill: parent
              anchors.margins: 5
              highlightFollowsCurrentItem: true
              currentIndex: -1
      
              model: cppIndex
              delegate: Text {
                  text: modelData
                  color: "white"
                  width: listView.width
                  clip: true
      
                  MouseArea {
                      anchors.fill: parent
                      onClicked: {
                          listView.currentIndex = index
                          listView.forceActiveFocus()
                      }
                  }
              }
      
              highlight: Rectangle {
                  color: "gray"
                  opacity: 0.5
                  border.color: indexView.border.color
                  radius: 5
              }
          }
      }
      
      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @grheard Please always provide a small compilable example which will exactly show the problem. Some of the properties in your example are undefined.
      First guess would be to set clip: true for ListView itself and not its delegate.

      157

      G 1 Reply Last reply
      1
      • p3c0P p3c0

        @grheard Please always provide a small compilable example which will exactly show the problem. Some of the properties in your example are undefined.
        First guess would be to set clip: true for ListView itself and not its delegate.

        G Offline
        G Offline
        grheard
        wrote on last edited by
        #3

        @p3c0 said:

        @grheard Please always provide a small compilable example which will exactly show the problem. Some of the properties in your example are undefined.
        First guess would be to set clip: true for ListView itself and not its delegate.

        Sorry. I will provide working examples in the future.

        Setting clip for the listview did work in keeping it from drawing outside of the boundaries, but now it draws the a partial entry for that part that would be inside the boundary. I can live with that... for now. I don't know why I didn't think of clip. Since, as you saw, I do have clip set on the Text delegate to keep it from drawing beyond the boundaries.

        Thanks.

        p3c0P 1 Reply Last reply
        0
        • G grheard

          @p3c0 said:

          @grheard Please always provide a small compilable example which will exactly show the problem. Some of the properties in your example are undefined.
          First guess would be to set clip: true for ListView itself and not its delegate.

          Sorry. I will provide working examples in the future.

          Setting clip for the listview did work in keeping it from drawing outside of the boundaries, but now it draws the a partial entry for that part that would be inside the boundary. I can live with that... for now. I don't know why I didn't think of clip. Since, as you saw, I do have clip set on the Text delegate to keep it from drawing beyond the boundaries.

          Thanks.

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @grheard It didn't work because the requirement is to clip beyond the ListView's boundary and not the delegate's one. And so setting clip for ListView did the trick.

          157

          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