How do I apply the style to a TextField in QML? It seems “style” attribute isn't available

后端 未结 1 880
我寻月下人不归
我寻月下人不归 2020-12-01 21:49

I am trying to apply some styles to a new qt 5.7 application I am working on and the following is not working at all. It gives the error: qrc:/SignInView.qml:67 Cannot assig

相关标签:
1条回答
  • 2020-12-01 22:10

    In Qt Quick Controls 2, there is no such property as TextField::style. In general, there is no way to use the style objects from Qt Quick Controls 1 with Qt Quick Controls 2. The APIs between the two major versions of Qt Quick Controls are not compatible. See the following documentation pages for more details:

    • Differences between Qt Quick Controls
    • Styling Qt Quick Controls 2
    • Customizing Qt Quick Controls 2

    A new API-incompatible major version was introduced, because there is basically no way to make the heavily Loader-based architecture of Qt Quick Controls 1 perform reasonably well. Therefore all that dynamic loading of Components was ditched in Qt Quick Controls 2. The delegates that used to be dynamically instantiated from Components provided by a dynamically loaded style object are now part of the control instead, instantiated "in place". In essence:

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

    vs.

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

    You can read more about the history here. In particular, this post highlights the fundamental structural changes in Qt Quick Controls 2.

    0 讨论(0)
提交回复
热议问题