英文:
The current style does not support customization of this control
问题
以下是翻译好的部分:
我有一段 qml
代码,在使用 QT 6.0.4
构建时可以正常执行,但在使用 QT 6.5.1
构建时会提示运行时错误。
完整的错误如下:
QML 矩形:当前样式不支持自定义此控件(属性:“background” 项目:QQuickRectangle(0x22c49ddefc0,parent=0x0,geometry=0,0 100x40))。请自定义非本地样式(如 Basic、Fusion、Material 等)。
以下是代码的一部分,其中包含了 background
样式:
Button {
id: listen_btn
text: "Press Me"
font.pixelSize: 18
background: Rectangle {
implicitWidth: 100
implicitHeight: 40
border.width: 1
}
}
英文:
I've a qml
code which executes fine when build in QT 6.0.4
but prompt me a runtime error when i build it using QT 6.5.1
.
The complete error is the following:
QML Rectangle: The current style does not support customization of this control (property: "background" item: QQuickRectangle(0x22c49ddefc0, parent=0x0, geometry=0,0 100x40)). Please customize a non-native style (such as Basic, Fusion, Material, etc)
Below is the portion of code in which the background
style is present.
Button {
id: listen_btn
text: "Press Me"
font.pixelSize: 18
background: Rectangle {
implicitWidth: 100
implicitHeight: 40
border.width: 1
}
答案1
得分: 1
这个警告是关于尝试自定义本机样式的问题。
请看这里:QTBUG-109438
这是附加的更改评论所说的。查看最后一段以解决您的问题 QT_QUICK_CONTROLS_IGNORE_CUSTOMIZATION_WARNINGS
,但正如评论所说“自定义本机样式要自行承担风险”。
> 当用户自定义本机样式时发出警告
>
> 自从Qt 6以来,默认样式不再是Basic样式,而是取决于应用程序运行的平台。此外,引入了本机样式(不打算进行自定义)意味着自定义控件的用户可能会遇到视觉问题,并且不理解原因。
>
> 该补丁部分解决了此问题,当自定义本机控件时(即重写委托时)会发出警告:
>
> "qrc:/main.qml:11:22: QML QQuickItem: 当前样式不支持自定义此控件(属性:“contentItem”项目:QQuickItem(0x1637375d210,父项=0x0,几何=0,0 0x0))。请自定义非本机样式(如Basic、Fusion、Material等)。有关更多信息,请参见:
> https://doc.qt.io/qt-6/qtquickcontrols2-customize.html#customization-reference"
>
>...
>
> [ChangeLog][重要行为更改] 现在会警告自定义本机样式。应用于自定义目的的应该是非本机样式(如Basic),或者是自定义样式。如果您了解风险并仍想自定义这些控件,可以通过设置
> QT_QUICK_CONTROLS_IGNORE_CUSTOMIZATION_WARNINGS 为1来忽略警告。
为了选择与默认样式不同的控件样式,根据您的用例有多个选项。请查看文档在QtQuick Controls中使用样式。
最简单的方法是使用 import QtQuick.Controls.Basic
。
英文:
This warning is about attempting to customize native style.
Have a look here: QTBUG-109438
This is what the attached change comment says. Take a look at the last paragraph to fix your issue QT_QUICK_CONTROLS_IGNORE_CUSTOMIZATION_WARNINGS
, but as the comment says "customize native styles on your own risk".
> Warn users when they customize native styles
>
> Since Qt 6, the default style is no longer the Basic style, but
> instead depends on the platform the application is run on. In
> addition, the introduction of the native styles (which are not
> designed to be customized) means that users customizing controls can
> run into visual issues and not understand why.
>
> This patch partially addresses this issue by warning when a native
> control is customized (i.e. a delegate is overridden):
>
> "qrc:/main.qml:11:22: QML QQuickItem: The current style does not
> support customization of this control (property: "contentItem" item:
> QQuickItem(0x1637375d210, parent=0x0, geometry=0,0 0x0)). Please
> customize a non-native style (such as Basic, Fusion, Material, etc).
> For more information, see:
> https://doc.qt.io/qt-6/qtquickcontrols2-customize.html#customization-reference"
>
>...
>
> [ChangeLog][Important Behavior Changes] Customization of native styles
> will now result in warnings. Non-native styles (such as Basic) should
> be used for customization purposes, or a custom style. If you are
> aware of the risks and still want to customize these controls, you can
> ignore the warnings by setting
> QT_QUICK_CONTROLS_IGNORE_CUSTOMIZATION_WARNINGS to 1.
In order to pick a different control style than the default one, there are multiple options depending on your use case. Have a look at the documentation Using styles in QtQuick Controls.
The simplest would be to use import QtQuick.Controls.Basic
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论