【问题标题】:TextAreaStyle cannot be assigned to style propertyTextAreaStyle 不能分配给样式属性
【发布时间】:2016-08-22 14:16:37
【问题描述】:

我在使用 style 属性更改可滚动 TextArea 的文本颜色时遇到问题。

我还添加了 .pro 文件中包含的模块:

QT += qml quick core quickcontrols2

这是我的 .qml 文件的样子:

 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 { }
    }
 }
 }

运行此示例时收到的错误消息:

QQmlApplicationEngine 加载组件失败 qrc:/main.qml:38 无法分配给不存在的属性“style”

我想我缺少一些依赖项,但在文档中找不到任何指向正确方向的内容。

【问题讨论】:

标签: qt qml qtquick2 qtquickcontrols2


【解决方案1】:

@BaCaRoZzo 的评论作为社区答案发布。


style 属性在控件 2 中不可用。样式在控件中内联。见here

您也可以删除 import QtQuick.Controls.Styles 1.4,因为它对您未导入的控件 1.x 的样式很有必要。

【讨论】:

    猜你喜欢
    • 2018-09-01
    • 1970-01-01
    • 2016-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-01
    相关资源
    最近更新 更多