1

I have a problem using the style property to change the text color of a scrollable TextArea.

I also added the included modules from the .pro file:

QT += qml quick core quickcontrols2

This is what my .qml file looks like:

 import QtQuick 2.7 
 import QtQuick.Controls 2.0
 import QtQuick.Controls.Styles 1.4
 import QtQuick.Layouts 1.1
 import QtQuick.Controls.Material 2.0
 import QtGraphicalEffects 1.0

 ApplicationWindow {
 visible: true
 width: 640
 height: 480
 title: qsTr("Test")

 Page {
     width: parent.width
     height: parent.height
     background: Rectangle {
         color: "#000000"
         width: parent.width
         height: parent.height
     }

    Flickable {
        id: flickable
        anchors.bottom: parent.bottom
        width: parent.width-50
        flickableDirection: Flickable.VerticalFlick
        height: 200

        TextArea.flickable: TextArea {
            id: pane1
            text: "This is some text"
            font.bold: false
            font.pointSize: 10
            wrapMode: Text.WordWrap
            clip: true

            style: TextAreaStyle {
                textColor: "#4F4F4F"
            }

            background: Rectangle {
                color: "#FFFFFF"
                width: parent.width
                height: parent.height
            }
        }

        ScrollBar.vertical: ScrollBar { }
    }
 }
 }

The Error message I get when running this example:

QQmlApplicationEngine failed to load component qrc:/main.qml:38 Cannot assign to non-existent property "style"

I guess I am missing some dependency, but couldn't find anything in the documentation pointing me into the right direction.

jpnurmi
  • 5,716
  • 2
  • 21
  • 37
Max
  • 852
  • 1
  • 9
  • 19
  • 2
    `style` property is not available in controls 2. Styling is inlined in the control. See [here](http://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-textarea). You can also remove `import QtQuick.Controls.Styles 1.4` since it is necessary to styling controls 1.x, which you didn't import. – BaCaRoZzo Aug 22 '16 at 14:58
  • Do you wanna answer with that, @BaCaRoZzo? – Mitch Aug 29 '16 at 19:46
  • Possible duplicate of [How do I apply the style to a TextField in QML? It seems "style" attribute isn't available](http://stackoverflow.com/questions/39052139/how-do-i-apply-the-style-to-a-textfield-in-qml-it-seems-style-attribute-isnt) – Mitch Sep 18 '16 at 20:24

1 Answers1

3

Posting @BaCaRoZzo's comment as a community answer.


style property is not available in controls 2. Styling is inlined in the control. See here.

You can also remove import QtQuick.Controls.Styles 1.4 since it is necessary to styling controls 1.x, which you didn't import.

Delgan
  • 18,571
  • 11
  • 90
  • 141