我想將一些樣式應用於我正在處理的新qt 5.7應用程序,而下面的程序根本不起作用。它給出了錯誤: qrc:/SignInView.qml:67不能分配給不存在的屬性「風格」 而我無法在設計模式中出於同樣的原因進行編輯。如何將樣式應用於QML中的TextField?看起來「樣式」屬性不可用
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
}
}
}
}
}
}
我一直是想以此爲榜樣:
http://doc.qt.io/qt-5/qml-qtquick-controls-styles-textfieldstyle.html
它未能在Qt Creator中給予該樣式不存在錯誤的樣式屬性。 我認爲這是我的圖書館沒有加載或可能是我設置的環境。 我沒有按鈕或任何其他地方的風格。我假設如果我有進口它會工作,但事實並非如此。
SO上的一個相關問題在這裏:QML - How to change TextField font size 但是,這裏似乎只是工作。