可以在快速控制 2.0 应用程序中使用 TableView 吗? 这将需要同时进行以下两个导入:
import QtQuick.Controls 1.4
import QtQuick.Controls 2.0
我会得到任何副作用吗?
另一个相关问题:似乎TableView属于Quick Controls 1.0集。是吗?这是否意味着如果可以使用 TableView,则可以在快速控制 2.0 应用程序中使用所有快速控件 1.0 控件?
虽然可以在同一应用程序中混合使用Qt Quick Controls 1和2,但最大的问题是Qt Quick Controls 1与Qt的自动高DPI缩放不兼容,而Qt Quick Controls 2的可扩展性则基于此。因此,运行这种混合两者的应用程序可能无法在高 DPI 显示器上提供理想的结果。
鉴于Qt Quick Controls 1TableView
存在严重的性能问题,一种可能的替代方案是使用Qt Quick core的普通ListView
,并将Row
作为委托。在Qt 5.9及更高版本中,可以显式指定内容宽度和轻拂方向,以便垂直ListView
也可以水平轻拂。这是一个过于简单的多列列表示例,您已经可以在最新的Qt 5.9测试版中试用:
import QtQuick 2.9
import QtQuick.Controls 2.2
ApplicationWindow {
id: window
width: 360
height: 360
visible: true
ListView {
id: listView
anchors.fill: parent
contentWidth: headerItem.width
flickableDirection: Flickable.HorizontalAndVerticalFlick
header: Row {
spacing: 1
function itemAt(index) { return repeater.itemAt(index) }
Repeater {
id: repeater
model: ["Quisque", "Posuere", "Curabitur", "Vehicula", "Proin"]
Label {
text: modelData
font.bold: true
font.pixelSize: 20
padding: 10
background: Rectangle { color: "silver" }
}
}
}
model: 100
delegate: Column {
id: delegate
property int row: index
Row {
spacing: 1
Repeater {
model: 5
ItemDelegate {
property int column: index
text: qsTr("%1x%2").arg(delegate.row).arg(column)
width: listView.headerItem.itemAt(column).width
}
}
}
Rectangle {
color: "silver"
width: parent.width
height: 1
}
}
ScrollIndicator.horizontal: ScrollIndicator { }
ScrollIndicator.vertical: ScrollIndicator { }
}
}
当然,这种简化的多列列表不提供诸如可移动和可调整大小的列以及其他内置于旧TableView
类型中的花里胡哨的功能。另一方面,性能处于完全不同的水平,因此,如果您的目标是在具有无限资源的计算机上运行的经典桌面环境以外的其他内容,则此路线可能值得考虑。;)
import QtQuick.Controls 1.4 as C
import QtQuick.Controls 2.0
C.TableView { //controls 1.4
Button { //controls 2.0
}
}
这将帮助您避免两个控件之间发生任何不必要的冲突