2

I have a QML TextArea for which I'd like a wider scrollbar. TextArea inherits from ScrollView, and it appears that the only style member in the TextArea class is inherited from ScrollView, so I thought I could just assign a ScrollViewStyle to the TextView's style member.

However, assigning this suggested ScrollViewStyle example to my TextArea's style member triggers error messages and makes the screen flicker oddly.

Here are the error messages:

 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

What's going on? How do I assign a ScrollViewStyle to the TextArea properly (assuming this is indeed the problem)? (E.g., can I explicitly scope the style assignment somehow? ScrollView.style: ScrollViewStyle { ... gives the error "Non-existent attached object.") Alternatively, is there a simpler way to just make the scroll bar wider without getting into this whole mess?

I'm using 64-bit Qt 5.5.1 on Debian 7 Wheezy.

Community
  • 1
  • 1
Kyle Strand
  • 15,941
  • 8
  • 72
  • 167
  • Also `TextAreaStyle` Inherits from `ScrollViewStyle`, which means the former has at least all the properties of the latter: you can simply rename the style `Item` from that link to `TextAreaStyle` and that's it, it should work out of the box. The parent style is probably missing some properties (the `undefined` warnings). – BaCaRoZzo Apr 12 '16 at 01:03
  • @BaCaRoZzo Ah! Thank you. That works perfectly, without even needing to define any extra properties. – Kyle Strand Apr 12 '16 at 02:23

1 Answers1

3

ScrollViewStyle shouldn't be assigned to the style member of a non-ScrollView class, even if it inherits from ScrollView. The QML component inheritance hierarchy is mirrored by the style inheritance hierarchy, so (as pointed out by BaCaRoZzo in a comment) the style member of a TextArea is actually a TextAreaStyle--which inherits from ScrollViewStyle.

So the solution is simply to define a TextAreaStyle, but only set the properties relevant to the ScrollViewStyle. Changing the word ScrollViewStyle to TextAreaStyle in the linked example is sufficient to accomplish this.

Kyle Strand
  • 15,941
  • 8
  • 72
  • 167