[英]Qt Quick Controls 2 and TableView
在Quick Controls 2.0應用程序中使用TableView是否可以? 這將需要兩個導入:
import QtQuick.Controls 1.4
import QtQuick.Controls 2.0
我會得到任何副作用嗎?
另一個相關的問題:似乎TableView屬於Quick Controls 1.0集。 是嗎? 是否意味着如果可以使用TableView,那么可以使用Quick Controls 2.0應用程序中的所有Quick Controls 1.0控件嗎?
雖然可以在同一個應用程序中混合使用Qt Quick Controls 1和2,但最大的問題是Qt Quick Controls 1與Qt的自動高DPI縮放不兼容,而Qt Quick Controls 2的可擴展性基於此。 因此,運行混合這兩者的應用程序可能無法在高DPI顯示器上提供理想的結果。
鑒於Qt Quick Controls 1 TableView
存在嚴重的性能問題,一種可能的替代方法是使用Qt Quick核心的普通ListView
和Row
作為委托。 使用Qt 5.9及更高版本,可以明確指定內容寬度和輕彈方向,以便也可以水平輕彈垂直ListView
。 這是一個過於簡單的多列列表示例,您已經可以嘗試使用最新的Qt 5.9 beta:
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
}
}
這將幫助您避免兩個控件之間的任何不必要的沖突
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.