【问题标题】:My custom widget is not shown in Qt Creator / Qt Designer but it is shown when I execute the program我的自定义小部件未显示在 Qt Creator / Qt Designer 中,但在我执行程序时显示
【发布时间】:2020-03-02 00:51:31
【问题描述】:

我想要一个QTabWidget,其中包含一个包含自定义小部件的选项卡。

  1. 我创建了一个自定义小部件(由 .ui、.h 和 .cpp 文件组成)

  2. 我在QTabWidget的首页添加了这个自定义的Widget,但是QtCreator的设计器中没有显示这个Widget的内容。

  3. 我将我的自定义小部件推广为Tab1Custom

当我运行程序时,此设置编译并按预期工作,但我的自定义控件没有显示在 QtCreator 的设计器中。

如何使我的自定义控件显示在 QtCreator 的设计器中?

这是 MainWindow.ui 的第一部分:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>my title </string>
  </property>
  <widget class="QWidget" name="centralWidget">
   <widget class="QTabWidget" name="tabWidget">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>10</y>
      <width>801</width>
      <height>551</height>
     </rect>
    </property>
    <property name="currentIndex">
     <number>0</number>
    </property>
    <widget class="Tab1Custom" name="myTab1">
     <attribute name="title">
      <string>My Tab number 1</string>
     </attribute>
    </widget>
    ....

【问题讨论】:

标签: qt qt-designer qt5.6


【解决方案1】:

这就是您使用自定义小部件并对其进行推广时的工作方式。为了让您的小部件绘制内容,您必须创建一个 DLL 来扩展 Qt 设计器。查看“Creating Custom Widgets for Qt Designer”了解更多信息。

在大多数情况下,我认为这样做不值得。一般来说,它只显示一个空白小部件或您推广的任何基本小部件都很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-16
    • 1970-01-01
    • 2022-07-02
    • 1970-01-01
    相关资源
    最近更新 更多