qt - 在设置 TableView Scroll 样式后,我在 QML 中收到警告
问题描述
我正在使用以下代码在 TableView 组件中设置处理程序的样式:
TableView {
style: ScrollViewStyle{
handle: Rectangle {
implicitWidth: globals.scrollBar.handlerWidth
implicitHeight: globals.scrollBar.handlerWidth
color: globals.scrollBar.handlerColor
}
}
}
属性是:
property var scrollBar: QtObject {
property int handlerWidth: 14
property color handlerColor: "#6b6b6b"
}
我尝试切换,int
但我仍然有同样的问题。color
var
全局变量在 main 上定义,如下所示:
Globals {
id: globals
}
现在我在 QT 中收到很多警告
file:///C:/Qt/5.11.1/mingw53_32/qml/QtQuick/Controls/Private/BasicTableView.qml:393:48: Unable to assign [undefined] to bool
file:///C:/Qt/5.11.1/mingw53_32/qml/QtQuick/Controls/Private/BasicTableView.qml:97:38: Unable to assign [undefined] to QQmlComponent*
file:///C:/Qt/5.11.1/mingw53_32/qml/QtQuick/Controls/Private/BasicTableView.qml:461:20: Unable to assign [undefined] to QColor
我错过了什么?
使用 qml 创建一个空的 qt (5.12) 应用程序的最小功能示例
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.3
import QtQuick.Controls.Styles 1.1
ApplicationWindow {
id: window
title: "Stack"
visible: true
width: 1400
ListModel {
id: libraryModel
ListElement {
title: "A Masterpiece"
author: "Gabriel"
}
ListElement {
title: "Brilliance"
author: "Jens"
}
ListElement {
title: "Outstanding"
author: "Frederik"
}
}
Page {
id: page
anchors.fill: parent
background: { color:"black" }
TableView{
style: ScrollViewStyle{//TODO: ScrollViewStyle is giving a lot of warnings
handle: Rectangle {
implicitWidth: 15
implicitHeight: 15
color: "#000000"
}
minimumHandleLength: 30
}
anchors.fill:parent
TableViewColumn {
role: "title"
title: "Title"
width: 100
}
TableViewColumn {
role: "author"
title: "Author"
width: 200
}
model: libraryModel
itemDelegate: Text
{
text: styleData.value
elide: Text.ElideRight
}
}
}
}
也许错误/警告与不兼容的进口有关?
解决方案
如果您使用TableView那么您必须使用TableViewStyle而不是ScrollViewStyle。并且您可以继续使用相同的属性,因为TableViewStyle继承自ScrollViewStyle:
style: TableViewStyle{
handle: Rectangle {
implicitWidth: 15
implicitHeight: 15
color: "#000000"
}
minimumHandleLength: 30
}
删除下面这行代码,因为 background 需要一个 Component,但也没有必要,因为 TableView 会占据整个 Page:
background: { color:"black" }
推荐阅读
- galera - Galera Donor 并切换到另一台主机进行插入语句
- svg - SVG 外部对象大小不一致
- java - 不返回void的java虚拟方法
- docker - 尝试在 docker 映像中设置 JAVA_HOME,不知道为什么它不起作用
- reactjs - OpenLayer 4 在地图上绘制箭头
- c# - 忽略大小写的 C# 表达式树或更低
- android - Firebase Firestore 如何识别离线读取
- node.js - 是否有组织/增强 Express.js 服务器的“标准”方式?
- sql - 从 PostgreSQL 中的字符串中删除数字索引
- java - 确定性类加载 - 加载类的控制线程