我正在尝试将一些样式应用于我正在处理的新 qt 5.7 应用程序,但以下内容根本不起作用。它给出了错误:qrc:/SignInView.qml:67 无法分配给不存在的属性“样式”,出于同样的原因,我无法在设计模式下对其进行编辑。
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 但在这里它似乎只是工作。