Qt Widgets 设计器

Qt Creator 在 模式下,在集成的 Designer 中自动打开所有 .ui 文件。Design Qt Widgets

在设计模式下打开 <span translate=Qt Widgets Designer" src="images/qtcreator-formedit.png" title="在设计模式下打开 Qt Widgets Designer"/>

使用Qt Widgets Designer 创建的 Widgets 和窗体可通过 Qt 信号和槽机制与编程代码无缝集成,该机制可让您轻松地为图形元素分配行为。在Qt Widgets Designer 中设置的所有属性都可以在代码中动态更改。此外,小部件推广和自定义插件等功能允许您在Qt Widgets Designer 中使用自己的小部件。

有关Qt Widgets Designer 的更多信息,请参阅Qt Widgets Designer 手册

一般来说,集成的Qt Widgets Designer 与独立的Qt Widgets Designer 具有相同的功能。下文将介绍两者的不同之处。

要学习如何使用集成的Qt Widgets Designer 创建基于Qt Widgets 的小型应用程序,请参加Qt 学院:Qt Creator 入门课程。

代码编辑器集成

要在窗体(Design 模式)和代码(Edit 模式)之间切换,请选择Shift+F4

您可以使用Qt Creator 创建槽函数的存根实现。在Design 模式下,右键单击部件打开上下文菜单,然后选择Go to Slot 。在列表中选择一个信号,转到现有的插槽函数或创建一个新的插槽函数。

管理图像资源

在单机版Qt Widgets Designer 中,图像资源是使用内置的Resource Editor 创建的。在Qt Creator 中,.ui 文件通常是一个项目的一部分,该项目可能有多个资源文件(.qrc)。这些文件通过Qt Creator 资源编辑器创建和维护。Qt Widgets DesignerResource Editor 被取消激活,图像资源显示在Qt Widgets DesignerResource Browser 中。

要从代码编辑器打开资源文件,请在上下文菜单中选择Follow Symbol Under Cursor ,或在光标停留在字符串文字上时选择F2

Qt Widgets Designer 指定设置

您可以将Qt Widgets Designer 中的视图拖放到屏幕上的新位置。

要指定Qt Widgets Designer 的设置,请

  • 选择首选项>Designer
  • 指定嵌入式设备配置文件,例如在Embedded Design 中指定样式、字体和屏幕分辨率。
  • Forms 中指定网格和预览表单的设置。
  • Template Paths 中指定用于保存模板的附加文件夹。

要预览设置,请选择Tools >Form Editor >Preview ,或选择Alt+Shift+R

使用设备配置文件预览表单

设备配置文件是一组描述移动设备的配置文件。它包括环绕表单的边框图像,描绘了移动设备及其按钮。

要使用设备配置文件预览表单,请选择Tools >Form Editor >Preview In ,然后选择一个设备配置文件。

添加设备配置文件

要添加设备配置文件,请执行以下操作

  1. 首选项>Designer

    Qt Widgets Designer 偏好设置

  2. Embedded Design 中,选择添加个人资料 (Add a profile) 打开Add Profile 对话框。

    添加简介对话框

  3. Name 中,输入设备名称。该名称在Preview In 中显示为一个选项。
  4. Family 中,选择要使用的字体。
  5. Point Size 中,选择字体大小。
  6. Style 中,选择预定义样式之一。
  7. Device DPI 中,选择一个预定义的 DPI 值,或User defined 指定一个自定义值。
  8. 选择OK ,将设备配置文件添加到列表中。

要从 .qdp 文件导入设备配置文件,请选择Open 。要将它们保存为 .qdp 文件,请选择Save

另请参阅 教程:Qt Widgets 应用程序添加Qt Widgets Designer 插件

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.