QML TextView 改变滚动条样式?

QML TextView change scroll-bar style?

我有一个 QML TextArea,我想要一个更宽的滚动条。 TextArea 继承自 ScrollViewTextArea class 中唯一的 style 成员似乎是 inherited from ScrollView,所以我想我可以将 ScrollViewStyle 分配给 TextViewstyle 成员。

但是,将 分配给我的 TextAreastyle 成员会触发错误消息并使屏幕奇怪地闪烁。

错误信息如下:

 file:///<qtpath>/Qt/5.5.1/5.5/gcc_64/qml/QtQuick/Controls/TextArea.qml:766:32: Unable to assign [undefined] to QColor
 file:///<qtpath>/Qt/5.5.1/5.5/gcc_64/qml/QtQuick/Controls/TextArea.qml:765:29: Unable to assign [undefined] to QColor
 file:///<qtpath>/Qt/5.5.1/5.5/gcc_64/qml/QtQuick/Controls/TextArea.qml:764:20: Unable to assign [undefined] to QColor
 file:///<qtpath>/Qt/5.5.1/5.5/gcc_64/qml/QtQuick/Controls/TextArea.qml:763:19: Unable to assign [undefined] to QFont
 file:///<qtpath>/Qt/5.5.1/5.5/gcc_64/qml/QtQuick/Controls/TextArea.qml:762:25: Unable to assign [undefined] to int
 file:///<qtpath>/Qt/5.5.1/5.5/gcc_64/qml/QtQuick/Controls/TextArea.qml:725:24: Unable to assign [undefined] to QColor

这是怎么回事?如何正确地将 ScrollViewStyle 分配给 TextArea (假设这确实是问题所在)? (例如,我可以以某种方式显式地确定 style 赋值范围吗?ScrollView.style: ScrollViewStyle { ... 给出错误“Non-existent attached object”。)或者,是否有更简单的方法来 进行滚动酒吧更宽 而不会陷入这整个混乱?

我在 Debian 7 Wheezy 上使用 64 位 Qt 5.5.1。

ScrollViewStyle 不应分配给非 ScrollView class、style 成员,即使它继承自 ScrollView。 QML 组件继承层次结构由样式继承层次结构 镜像 ,因此(正如 BaCaRoZzo 在评论中指出的那样)TextAreastyle 成员实际上是a TextAreaStyle--继承自 ScrollViewStyle.

所以解决办法就是定义一个TextAreaStyle,但只设置与ScrollViewStyle相关的属性。在链接示例中将单词 ScrollViewStyle 更改为 TextAreaStyle 足以实现此目的。