Guest User

qtbug1.qml

a guest
Nov 12th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 1.84 KB | None | 0 0
  1.  
  2. import QtQuick 6.2
  3.  
  4. Window {
  5.     id: root
  6.     visible: true
  7.     width: 800
  8.     height: 600
  9.     title: qsTr("Qt 6.2.1 ListView Bug")
  10.  
  11.     Component {
  12.         id: listViewHeader
  13.         Rectangle {
  14.             z: 2
  15.             color: "black"
  16.             clip: true
  17.             height: columnName.implicitHeight + 10
  18.             width: myListView.width
  19.             Text {
  20.                 id: columnName
  21.                 color: "white"
  22.                 text: qsTr("Row Name")
  23.             }
  24.         }
  25.     }
  26.  
  27.     Component {
  28.         id: listDelegate
  29.         Rectangle {
  30.             color: Qt.rgba(Math.random(), Math.random(), Math.random(), 0.25)
  31.             clip: true
  32.             height: rowText.implicitHeight + 10
  33.             width: myListView.width
  34.             Text {
  35.                 id: rowText
  36.                 text: model.display
  37.             }
  38.         }
  39.     }
  40.  
  41.     ListView {
  42.         id: myListView
  43.         anchors.fill: parent
  44.  
  45.         // BUG!  If the ListView has a header and the view is not moved so that item 0
  46.         // is still shown when the model is reset, then the ListView renders a phantom
  47.         // item 0 that is no longer in the model.  If new model has an item 0 it is
  48.         // rendered right over the top of the phantom item 0.
  49.         header: listViewHeader
  50.         headerPositioning: ListView.OverlayHeader
  51.  
  52.         model: pythonModel
  53.         delegate: listDelegate
  54.         clip: true
  55.         focus: true
  56.     }
  57.  
  58.     Connections {
  59.         target: pythonModel
  60.         function onModelAboutToBeReset() {
  61.             console.log("onModelAboutToBeReset model.rowCount=", pythonModel.rowCount())
  62.         }
  63.     }
  64.  
  65.     Connections {
  66.         target: pythonModel
  67.         function onModelReset() {
  68.             console.log("onModelReset model.rowCount=", pythonModel.rowCount())
  69.         }
  70.     }
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment