Culling items that are outside the visible area

后端 未结 2 1151
轻奢々
轻奢々 2020-12-18 11:58

From the docs:

The default renderer does not do any CPU-side viewport clipping nor occlusion detection. If something is not supposed to be visible, it

相关标签:
2条回答
  • 2020-12-18 12:43

    Here is a trivial example you can extend upon:

    Window {
      visible: true
      width: 640
      height: 480
    
      Rectangle {
        anchors.centerIn: parent
        width: 200
        height: 200
        color: "yellow"
    
        Flickable {
          id: view
          anchors.fill: parent
          contentWidth: 200
          contentHeight: col.height
          property real span : contentY + height
          Column {
            id: col
            x: 90
            spacing: 2
            Repeater {
              model: 50
              delegate: Rectangle {
                width: 10
                height: 10
                color: inView ? "blue" : "red"
                property bool inView: y > view.contentY && y < view.span
              }
            }
          }
        }
      }
    }
    

    Obviously, a full-proof solution would also include the item's height in the calculation. You can also do the check in the x axis if necessary.

    0 讨论(0)
  • 2020-12-18 12:46

    To add to dtech's answer, I just learned that there are QML components, such as GridView and ListView, that do culling automatically.

    0 讨论(0)
提交回复
热议问题