首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Qt Quick Controls 2和TableView

Qt Quick Controls 2和TableView
EN

Stack Overflow用户
提问于 2017-04-15 16:37:12
回答 2查看 11.6K关注 0票数 15

是否可以在Quick Controls 2.0应用程序中使用TableView?这将需要同时具有两个导入:

代码语言:javascript
复制
import QtQuick.Controls 1.4
import QtQuick.Controls 2.0

我会有任何副作用吗?

另一个相关的问题: TableView似乎属于Quick Controls 1.0 set。是吗?这是否意味着如果可以使用TableView,那么就可以在Quick Controls 2.0应用程序中使用所有的Quick Controls1.0控件?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-05-09 03:39:05

虽然可以在同一应用程序中混合使用Qt Quick Controls 1和Qt Quick Controls 2,但最大的问题是Qt Quick Controls 1与Qt的自动高DPI缩放不兼容,而Qt Quick Controls 2的可扩展性基于此。因此,在高DPI的显示器上运行这两者的应用程序可能不会给出理想的结果。

鉴于Qt Quick Controls 1 TableView有严重的性能问题,一种可能的替代方案是使用来自Qt Quick core的纯ListView,并使用Row作为代理。在Qt5.9和更高版本中,可以显式地指定内容宽度和轻弹方向,以便垂直ListView也可以水平轻弹。下面是一个非常简单的多列列表示例,你可以在最新的Qt 5.9beta中尝试一下:

代码语言:javascript
复制
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类型中的其他花哨的特性。另一方面,性能处于完全不同的水平,所以如果您的目标是在拥有无限资源的计算机上运行的传统桌面环境之外的其他环境,则此路线可能值得考虑。;)

票数 21
EN

Stack Overflow用户

发布于 2017-11-07 08:17:50

代码语言:javascript
复制
import QtQuick.Controls 1.4 as C
import QtQuick.Controls 2.0

C.TableView {  //controls 1.4
   Button {  //controls 2.0
   }
}

这将帮助您避免两个控件之间发生任何不必要的冲突

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43423981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档