Qt5 (QML) 中的 ui.qml 文件有什么用? [英] What is the use of the ui.qml files in Qt5 (QML)?

查看:11
本文介绍了Qt5 (QML) 中的 ui.qml 文件有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,.qml 文件可用于定义 UI,这似乎覆盖了 ui.qml 文件中写入的任何内容.那么,ui.qml文件到底有什么用呢?

As far as I can see the .qml files can be used to define the UI, which seems to override whatever is written in ui.qml file. So, what exactly is the use of the ui.qml file?

我正在使用 Qt5 和 Qt Creator.

I'm using Qt5 with Qt Creator.

推荐答案

.ui.qml 文件的存在是为了帮助 Qt Quick Designer 解决问题.例如,普通的 QML 文件可以包含 JavaScript 表达式,但 Qt Quick Designer 很难使用这些表达式.另一方面,普通的 QML 没有那么困难,并且更接近于 .ui 文件的小部件等价物 - 一个详细说明用户界面中一组项目的文档,而不是逻辑在他们身后.

The .ui.qml file exists to help Qt Quick Designer out. Normal QML files can contain JavaScript expressions, for example, but these are difficult for Qt Quick Designer to work with. Plain QML, on the other hand, is not as difficult, and is closer to the widgets equivalent of .ui files - a document that details a set of items in a user interface, not so much the logic behind them.

该功能 是几年前提出的在博客上:

经典的小部件设计器是围绕声明式和命令式逻辑之间的区别而构建的.声明形式是可设计的并存储在 .ui 文件中.

The classical Widget Designer is built around the distinction between declarative form and imperative logic. The declarative form is designable and stored in .ui files.

在 Qml 中,很容易混合声明式代码和命令式代码.如果您向 Qml 文件添加命令式指令(影响视觉方面),它们不再是纯粹的声明性指令,并且可视化编辑器中的可视化表示将中断.可视化编辑器需要一种将可视化描述转换回文本描述的方法.对于命令式代码,这通常是不可能的,Qt Quick Designer 甚至都不会尝试.

In Qml it is easy to mix declarative code and imperative code. If you add imperative instructions (affecting visual aspects) to your Qml files they are not purely declarative anymore and the visual representation in the visual editor will break. The visual editor needs a way to translate the visual description back into the text description. For imperative code this is not possible in general and the Qt Quick Designer does not even try.

QML 文档 文档指出:

从 Qt 5.4 开始,文档也​​可以具有文件扩展名.ui.qml".QML 引擎像处理标准 .qml 文件一样处理这些文件,并忽略扩展名的 .ui 部分.Qt Creator 将这些文件作为 Qt Quick Designer 的 UI 表单处理.这些文件只能包含 Qt Creator 定义的 QML 语言的子集.

Since Qt 5.4, a document can also have the file extension ".ui.qml". The QML engine handles these files like standard .qml files and ignores the .ui part of the extension. Qt Creator handles those files as UI forms for the Qt Quick Designer. The files can contain only a subset of the QML language that is defined by Qt Creator.

Qt Quick UI 表单:

您可以使用 Qt Creator 向导创建文件扩展名为 .ui.qml 的 UI 表单.UI 表单包含 QML 语言的纯声明性子集.建议您在设计模式下编辑表单.但是,将项目导出为别名属性只是商业功能,因此如果您使用的是 Qt Creator 的开源版本,则必须使用编辑模式来执行此操作.Qt Creator 通过显示错误消息来强制使用受支持的 QML 功能.

You can use Qt Creator wizards to create UI forms that have the filename extension .ui.qml. The UI forms contain a purely declarative subset of the QML language. It is recommended that you edit the forms in the Design mode. However, exporting items as alias properties is a commercial only feature, and therefore you must use the Edit mode to do it if you are using the open source version of Qt Creator. Qt Creator enforces the use of the supported QML features by displaying error messages.

不支持以下功能:

  • JavaScript 块
  • 函数定义
  • 函数调用(qsTr 除外)
  • 纯表达式以外的其他绑定
  • 信号处理程序
  • 根项以外的其他项中的状态
  • 不是从 QQuickItem 或 Item 派生的根项目

不支持以下类型:

  • 行为
  • 绑定
  • 画布
  • 组件
  • 着色器效果
  • 定时器
  • 变换
  • 过渡

这篇关于Qt5 (QML) 中的 ui.qml 文件有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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