User Interfaces

Qt具有创建用户界面的多种技术。尽管可以根据需要混合和匹配这些不同的技术,但一种方法通常比其他方法更适合于某种类型的用户界面。Qt Creator是混合不同用户界面技术的应用程序的一个很好的例子。实际上,它使用了下面描述的两种不同的方法。Qt Creator使用传统的Qt Widgets,例如菜单和对话框作为用户界面的基础,Qt Quick以及其他欢迎屏幕。以下部分简要介绍了用于创建用户界面的可用技术以及用于帮助选择最佳合适技术的比较表。

常见的重要UI主题

QML图形用户界面

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

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

QML应用程序的重要UI主题

图形控件

Qt Quick Controls模块是Qt 5.1中的新增功能,并提供一组UI元素以使用Qt Quick创建用户界面2。

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

基于Widget的用户界面

Qt Widgets是通常在桌面环境中找到的传统用户界面元素。这些小部件很好地集成到底层平台上,在Windows,Linux和Mac OSX上提供原生的look 'n' feel。这些小部件是成熟的,功能丰富的用户界面元素适合大多数静态用户界面。Qt Quick相比,这些小部件对于触摸屏和流畅的高度动画化的现代用户界面并不能很好地进行扩展。对于具有传统桌面中心用户界面的应用程序(例如办公室类型应用程序),这些小部件是不错的选择。

Qt Widgets中的重要概念

可视化数据

Qt提供了现成的C类和QML类型,用于以图表和图形的形式可视化数据,这些数据被称为分析数据的最佳方式。Qt Charts和{Qt Data Visualization}是使用2D和3D模型将数据可视化成为现实的两个Qt附加组件。

Displaying Web Content

Qt provides the Chromium-based WebEngine layout engine, which enable you to embed web content into the Qt application. The engine can be integrated into both Qt Widget-based and Qt Quick-based applications.

For more information about support for web content in Qt, see Integrating Web Content.

Comparison

Notice that choosing the appropriate technology for building an user interface is not always black and white. It depends on several criteria, such as other existing technologies used in a project or even 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 best suited tool for the job.

Qt Quick / Qt Quick ControlsQt WidgetsQt WebEngineComments
Used language(s)QML/JSC++HTML/CSS/JS
Native look'n'feelXXQt 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'feelX(X)(X)Qt 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 UIsXXQt Widgets do not scale well for animations. Qt Quick offers a convenient and natural way to implement animations in a declarative manner.
Touch screenXXQt 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 widgetsXQt 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 programming(X)XQt 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 developmentX(X)(X)Qt Quick is an excellent choice for rapid UI prototyping and development.
HW accelerated graphicsX(X)XQt 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 effectsXThe particle system and shader effects available in Qt Quick are more flexible. Qt Widgets offer very little in this area.
Rich text processing(X)XQt 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 contentXBoth Qt Quick and Qt Widgets provide components for presenting simple rich text, but Qt WebEngine is the right choice for presenting full-blown web content.

Internationalization and Translations

Qt provides excellent support for translating applications into local languages. Release managers, translators, and developers can use Qt translation tools to accomplish their tasks.