小缡绕谁前 |
2016-01-07 10:52 |
QML TableView拖动时不仅卡,还会内存泄露是怎么回事
import QtQuick 2.0 import QtQuick.Controls 1.1 Rectangle { width: 360 height: 500
ListModel { id: largeModel Component.onCompleted: { for (var i=0 ; i< 50 ; ++i) //Math.round(Math.random()*100) largeModel.append({"name":"name "+i , "age": "10", "gender": "test"})
for (i=0 ; i< 50 ; ++i) //Math.round(Math.random()*100) largeModel.append({"name":"name "+i , "age": "true", "gender": "test"}) for (i=0 ; i< 100 ; ++i) //Math.round(Math.random()*100) largeModel.append({"name":"name "+i , "age": "false", "gender": "test"}) } }
Component { id: editableDelegate Item {
Text { width: parent.width anchors.margins: 4 anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter elide: styleData.elideMode text: styleData.value !== undefined ? styleData.value : "" font.family: "微软雅黑" color: styleData.textColor visible: !styleData.selected } ComboBox{
id:delegatecombobox
model: [ "true", "false"] width: parent.width/2 height: parent.height-2 anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter
currentIndex: styleData.value==="true"? 0:1 visible: styleData.value==="true"||styleData.value==="false" } // Loader { // id: loaderEditor // anchors.fill: parent // anchors.margins: 4 // Connections { // target: loaderEditor.item // onAccepted: { // if (typeof styleData.value === 'number') // largeModel.setProperty(styleData.row, styleData.role, Number(parseFloat(loaderEditor.item.text).toFixed(0))) // else // largeModel.setProperty(styleData.row, styleData.role, loaderEditor.item.text) // } // } // sourceComponent: styleData.selected ? editor : null // Component { // id: editor // TextInput { // id: textinput // color: styleData.textColor // text: styleData.value // MouseArea { // id: mouseArea // anchors.fill: parent // hoverEnabled: true // onClicked: textinput.forceActiveFocus() // } // } // } // } } }
//////////////////////////////////////////////////////////////////////////////////////// TableView { anchors.rightMargin: 12 anchors.bottomMargin: 0 anchors.leftMargin: 12 anchors.topMargin: 24 model: largeModel anchors.margins: 12 anchors.fill:parent
clip: false TableViewColumn { role: "name" title: "Name" width: 120 } TableViewColumn { role: "age" title: "value" width: 120 } TableViewColumn { role: "gender" title: "test" width: 120 }
itemDelegate: editableDelegate
}
}
|
|