我的自定义控件在Qt Creator / Qt Designer中没有显示,但在执行程序时显示

3
我想要一个带有自定义小部件的。
  1. 我创建了一个自定义小部件(包括.ui、.h和.cpp文件)。

  2. 我将此自定义小部件添加到我的的第一页,但在QtCreator的设计师中没有显示出该小部件的内容。

  3. 我将我的自定义小部件提升为。

当我运行程序时,这个设置编译并按预期工作,但我的自定义控件不会在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>
    ....

相关页面在QtCreator文档中:为Qt Designer创建自定义小部件 - jrh
1个回答

1
这是使用自定义小部件并提升它的工作原理。为了让您的小部件显示内容,您必须创建一个DLL来扩展Qt Designer。请查看“为Qt Designer创建自定义小部件”以获取更多信息。
大多数情况下,我认为这样做不值得努力;一般来说,只显示空白小部件或您提升的基本小部件是可以接受的。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接