【问题标题】:How to override some properties of TableView.rowDelegate while keeping others default如何覆盖 TableView.rowDelegate 的某些属性,同时保持其他属性为默认值
【发布时间】:2015-08-29 22:31:09
【问题描述】:

我正在使用rowDelegate 来实现可变行高,如下所示。但是,它不使用选定/备用行的默认背景颜色。如何保留我不想覆盖的所有默认值?

TableView {
        id: messagesTable
        TableViewColumn {
            role: "severity"
            title: ""
            width: 20
            delegate: Image {
                anchors.centerIn: parent
                fillMode: Image.Pad
                source: iconSources[styleData.value.toLowerCase()]
            }
        }
        TableViewColumn {
            role: "message"
            title: "Message"
            width: 300
        }
        TableViewColumn {
            role: "source"
            title: "File"
            width: 150
        }
        TableViewColumn {
            role: "startLine"
            title: "Line"
            width: 40
        }
        TableViewColumn {
            role: "startColumn"
            title: "Column"
            width: 50
        }
        rowDelegate: Rectangle {
            width: childrenRect.width
            height: (messagesModel.get(styleData.row).lineCount || 1) * 20
        }
        model: messagesModel
    }

【问题讨论】:

    标签: qt qml qtableview


    【解决方案1】:

    你不能。

    使用 Qt Quick Controls 进行样式设置的一般规则是:一旦覆盖委托,就从头开始。例如,如果样式提供了 DefaultTableViewRowDelegate 类型,您可以构造它的一个实例,然后它就可以工作,但由于默认委托是内联编写的,您无法访问它们。

    【讨论】:

    • 那真是太可惜了。你知道我在哪里可以访问默认颜色吗?
    • 我看到QStyledItemDelegate...行代表没有类似的东西吗?
    • SystemPalette,但我不确定这是否会给你想要的颜色。桌面样式使用 Qt Widgets 的样式,您可能已经注意到了,但我很确定如果您想使用私有 API(对于 QPlatformTheme 等),您必须使用私有 API。
    • 看起来我至少可以从中获取文本选择颜色,这似乎是默认情况下用于选定表格行的颜色。谢谢!
    猜你喜欢
    • 2020-06-29
    • 2019-07-26
    • 1970-01-01
    • 2011-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-09
    相关资源
    最近更新 更多