How to apply style to TextField in QML? The style attribute seems to be unavailable.

I am trying to apply some styles to the new qt 5.7 application that I am working on, and the following does not work at all. This gives an error: qrc: /SignInView.qml: 67 It is not possible to assign a nonexistent "style" to the property, And I cannot edit it in design mode for the same reasons.

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.4

Page {
    id: page1
    ColumnLayout {
        id: columnLayout1
        height: 100
        anchors.right: parent.right
        anchors.left: parent.left
        anchors.top: parent.top

        Label {
            text: qsTr("Label")
            font.pointSize: 16
            horizontalAlignment: Text.AlignHCenter
            Layout.fillWidth: true
        }

        Image {
            id: image1
            width: 200
            height: 200
            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
            fillMode: Image.PreserveAspectCrop
            anchors.horizontalCenter: parent
            source: "qrc:/qtquickplugin/images/template_image.png"

            Button {
                id: button1
                text: qsTr("Button")
                anchors.bottomMargin: 10
                anchors.rightMargin: 10
                anchors.bottom: parent.bottom
                anchors.right: parent.right
            }
        }

        Rectangle {
            id: field1
            width: 200
            height: 40
            color: "#ffffff"
            Layout.fillWidth: true



            Label {
                id: label1
                text: qsTr("Full Name")
                anchors.topMargin: 0
                anchors.left: parent.left
                anchors.leftMargin: 5
                anchors.top: parent.top
            }
            TextField {
                style: TextFieldStyle {
                    textColor: "black"
                    background: Rectangle {
                        radius: 2
                        implicitWidth: 100
                        implicitHeight: 24
                        border.color: "#333"
                        border.width: 1
                    }
                }
            }
        }
    }
}

I am trying to follow this example:

http://doc.qt.io/qt-5/qml-qtquick-controls-styles-textfieldstyle.html

This does not match the style attribute in Qt Creator, giving an error that the style does not exist. I am assuming something with my libraries that are not loading, or maybe setting up the environment. I don’t have a button style or anywhere else. I suggested that if I have imports, it will work, but it is not.

SO: QML - TextField , , .

+4
1

Qt Quick Controls 2 , TextField::style. , Qt Quick Controls 1 Qt Quick Controls 2. API- Qt Quick Controls . . :

, API-, Qt Quick Controls 1 Loader. Component Qt Quick Controls 2. , Component, , , " ". :

TextField {
    style: TextFieldStyle {
        textColor: "white"
        background: Rectangle { color: "black" }
    }
}

.

TextField {
    color: "white"
    background: Rectangle { color: "black" }
}

. , Qt Quick Controls 2.

+15

Source: https://habr.com/ru/post/1651865/


All Articles