QML - 无法分配给不存在的属性“样式" [英] QML - Cannot assign to non-existent property "style"

查看:21
本文介绍了QML - 无法分配给不存在的属性“样式"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Qt 5.10.1 与 Qt Creator 4.5.1 一起使用,style 属性在元素中永远不可用.

I'm using Qt 5.10.1 with Qt Creator 4.5.1 and the style property is never available in elements.

例如这里显示 ButtonStyle QML 类型 ,我想做:

For example, as shown here ButtonStyle QML Type , I would like to do:

Button {
    text: "A button"
    style: ButtonStyle {...}
}

但是,我得到了错误:

无法分配给不存在的属性style"

Cannot assign to non-existent property "style"

我尝试了一个矩形,进度条,我得到了同样的错误.

I tried with a rectangle, progressbar and I get the same error.

编辑#1:

我确实拥有所有这些进口商品.如果缺少导入,我会在 ButtonStyle 上收到错误,但在 style 上会出现错误.

I do have all these imports. If the import was missing, I would get the error on ButtonStyle , but the error is on style.

import QtQuick 2.2
import QtQuick.Controls 2.3
import QtQuick.Dialogs 1.0
import QtGraphicalEffects 1.0
import QtQuick.Shapes 1.0
import QtQuick.Layouts 1.3
import QtQuick.Controls.Styles 1.4

推荐答案

QML中有2种Buttons:

There are 2 types of Buttons in QML:

在您的情况下,您正在导入 Qt QuickControls 2 按钮:import QtQuick.Controls 2.3,并且该按钮没有 style 属性.

In your case, you are importing the Qt QuickControls 2 Button: import QtQuick.Controls 2.3, and that Button does not have the style attribute.

如果你需要使用样式你必须导入:

If you need to use the style you must import:

import QtQuick.Controls 1.4

代替:

import QtQuick.Controls 2.3

<小时>

如果您使用 Qt Quick Controls 和 Qt Quick Controls 2 中的项目,您可以使用命名空间将它们分开:


If you are using items from Qt Quick Controls and Qt Quick Controls 2 you could separate them using a namespace:

import QtQuick.Controls 2.3 as QQC2
import QtQuick.Controls 1.4 as QQC1

QQC1.Button {
    text: "A button"
    style: ButtonStyle {...}
}

QQC2.another_item_of_Qt_Quick_Controls2{
}

这篇关于QML - 无法分配给不存在的属性“样式"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆