gpt4 book ai didi

qt - Qt5(QML)中的ui.qml文件有什么用?

转载 作者:行者123 更新时间:2023-12-01 19:48:15 55 4
gpt4 key购买 nike

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

我正在使用 Qt5 和 Qt Creator。

最佳答案

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

功能was proposed several years ago on the blog :

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.

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 Documents文档说明:

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 Forms :

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.

The following features are not supported:

  • JavaScript blocks
  • Function definitions
  • Function calls (except qsTr)
  • Other bindings than pure expressions
  • Signal handlers
  • States in other items than the root item
  • Root items that are not derived from QQuickItem or Item

The following types are not supported:

  • Behavior
  • Binding
  • Canvas
  • Component
  • Shader Effect
  • Timer
  • Transform
  • Transition

关于qt - Qt5(QML)中的ui.qml文件有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30652537/

55 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com