User Interfaces

Qt具有创建用户界面的多种技术。 尽管可以根据需要混合和匹配这些不同的技术,但一种方法通常比其他方法更适合于某种类型的用户界面。 Qt Creator是结合了传统的Qt小部件Qt Quick的应用程序的一个很好的例子。 小部件构成用户界面的基础,而Qt Quick则用于实现“欢迎”模式。 以下各节简要介绍了用于创建用户界面的可用技术,并提供了一个比较表来帮助选择最合适的技术。

常见的重要UI主题

QML Graphical User Interfaces

QML允许开发人员以声明的方式构建用户界面。 用户界面特别受益于复合QML对象和使用属性绑定配置它们的简单性。

Qt Quick是一个模块,提供用于创建用户界面的QML类型,例如具有自己的坐标系和渲染引擎的可视画布。 动画和过渡效果是Qt Quick中的一流概念,可以通过用于粒子和着色器效果的专用组件来补充视觉效果。

Important UI Topics for QML Applications

Graphical Controls

Qt Quick Controls模块(从Qt 5.1开始)提供了一组UI元素,用于使用Qt Quick 2为台式机和移动平台创建用户界面。 Qt Quick Controls 2模块(自Qt 5.7起)提供了轻量级QML类型,用于为嵌入式和移动设备创建高性能的用户界面。 与第一组控件相比,这些控件通过采用简化的样式体系结构来提高效率。 有关两组控件的比较,请参见Qt快速控件之间的差异

有关如何使用QML创建应用程序用户界面的更多信息,请访问QML用户界面页面。

Widget-based User Interfaces

Qt Widgets是传统的用户界面元素,通常在桌面环境中找到。 The widgets 很好地集成到了基础平台上,从而在Windows,Linux和Mac OSX上提供了原生的外观。 The widgets 已经成熟,并且具有丰富的用户界面元素,适用于大多数静态用户界面。 Qt Quick相比,这些窗口小部件无法很好地缩放触摸屏和流畅,高度动画化的现代用户界面。 对于具有传统桌面中心用户界面的应用程序(例如办公类型的应用程序),widgets 是不错的选择。

Qt Widgets 中的重要概念

可视化数据

Qt提供了现成的C++类和 QML 类型,以图表和图形的形式可视化数据,众所周知这是分析数据的最佳方法。 Qt ChartsQt Data Visualization是使使用2D和3D模型进行数据可视化成为现实的两个Qt附加组件。

显示网页内容

Qt提供基于Chromium的WebEngine布局引擎,使您可以将Web内容嵌入到Qt应用程序中。 该引擎可以集成到基于Qt Widget和基于Qt Quick的应用程序中。

有关在Qt中支持Web内容的更多信息,请参见集成Web内容

比较

Choosing the appropriate technology for building a user interface is not always easy. It depends on several variables, such as other technologies used in a project or target platform constraints. To some extent, many items in the following table can be implemented using any of the three available technologies. The following table aims to help you choose the tool best suited for the job.

Qt Quick / Qt Quick ControlsQt WidgetsQt WebEngineComments
Used language(s)QML/JSC++HTML/CSS/JS
Native look'n'feelQt Widgets and Qt Quick Controls integrate well to the underlying platform, providing a native look'n'feel on Windows, Linux, and macOS.
Custom look'n'feelQt Widgets provide means for customization via style sheets, but Qt Quick is a better performing choice for user interfaces that do not aim to look native.
Fluid animated UIsQt Widgets do not scale well for animations. Qt Quick offers a convenient and natural way to implement animations in a declarative manner.
Touch screenQt Widgets often require a mouse cursor for good interaction, whereas Qt Quick only provides primitive building blocks that were designed with touch interaction in mind. The WebView Qt Quick component has support for multi-touch gestures to interact with web content.
Standard industry widgetsQt Widgets provide all the bells and whistles, developed over two decades, needed for building standard industry type applications. Qt WebEngine Widgets provide widgets and additional classes to render and interact with web content.
Model/View programmingQt Quick provides convenient views, but Qt Widgets provide more convenient and complete framework. In addition to Qt Quick views, Qt Quick Controls provide a TableView.
Rapid UI developmentQt Quick is an excellent choice for rapid UI prototyping and development.
HW accelerated graphicsQt Widgets provide QGLWidget for rendering OpenGL graphics, and Qt WebEngine supports WebGL, but the OpenGL ES 2.0 or OpenGL 2.0 based Qt Quick Scene Graph has proven to provide the best performance for UIs and for integrating with OpenGL content.
Graphical effectsThe particle system and shader effects available in Qt Quick are more flexible. Qt Widgets offer very little in this area.
Rich text processingQt Widgets currently provide the most comprehensive base for implementing text editors. Qt's rich text document classes can also be utilized in Qt Quick and Qt Quick Controls' TextArea, but may require some C++ implementation.
Existing web contentBoth Qt Quick and Qt Widgets provide components for presenting simple rich text, but Qt WebEngine is the best choice for presenting full-blown web content.

国际化与翻译

Qt为将应用程序翻译成本地语言提供了出色的支持。 发布经理,翻译和开发人员可以使用Qt转换工具来完成其任务。