QDesignerCustomWidgetInterface Class Reference

[QtDesigner module]

该QDesignerCustomWidgetInterface类使Qt Designer来访问和构建自定义部件。More…

通过继承QPyDesignerCustomWidgetPlugin

Methods

  • __init__ (self)
  • __init__ (self, QDesignerCustomWidgetInterface)
  • QString codeTemplate (self)
  • QWidget createWidget (self, QWidget parent)
  • QString domXml (self)
  • QString group (self)
  • QIcon icon (self)
  • QString includeFile (self)
  • initialize (self, QDesignerFormEditorInterface core)
  • bool isContainer (self)
  • bool isInitialized (self)
  • QString name (self)
  • QString toolTip (self)
  • QString whatsThis (self)

Detailed Description

该QDesignerCustomWidgetInterface类使Qt Designer来访问和构建自定义部件。

QDesignerCustomWidgetInterface提供了自定义小部件的接口。这个类包含了一组必须被继承来返回小部件,比如它的类名和其头文件的名称基本信息的功能。其他功能必须实现在加载时初始化插件,构建自定义窗口小部件的实例Qt Designer来使用。

在实现自定义窗口小部件,您必须继承QDesignerCustomWidgetInterface到你的widget暴露在Qt Designer。例如,这是声明中使用的插件Custom Widget Plugin example它使一个模拟时钟定制窗口小部件要使用的Qt Designer

  1. class AnalogClockPlugin : public [QObject]($docs-qobject.html), public QDesignerCustomWidgetInterface
  2. {
  3. Q_OBJECT
  4. Q_INTERFACES(QDesignerCustomWidgetInterface)
  5. public:
  6. AnalogClockPlugin([QObject]($docs-qobject.html) *parent = 0);
  7. bool isContainer() const;
  8. bool isInitialized() const;
  9. [QIcon]($docs-qicon.html) icon() const;
  10. [QString](qstring.html) domXml() const;
  11. [QString](qstring.html) group() const;
  12. [QString](qstring.html) includeFile() const;
  13. [QString](qstring.html) name() const;
  14. [QString](qstring.html) toolTip() const;
  15. [QString](qstring.html) whatsThis() const;
  16. [QWidget](qwidget.html) *createWidget([QWidget](qwidget.html) *parent);
  17. void initialize([QDesignerFormEditorInterface]($docs-qdesignerformeditorinterface.html) *core);
  18. private:
  19. bool initialized;
  20. };

需要注意的是类定义的特定于这个特定的自定义插件的唯一部分是类名。此外,由于我们正在实施一个接口,我们必须确保它是由已知的元对象系统中使用Q_INTERFACES()宏。这使Qt Designer使用qobject_cast( )函数用什么来查询所支持的接口,但一QObject指针。

Qt Designer加载一个自定义的widget插件,它会调用该接口的initialize( )函数,使之能够成立,它可能需要的任何资源。这个函数被调用了QDesignerFormEditorInterface参数,它提供了插件与网关对所有的Qt Designer的API 。

Qt Designer通过调用插件的构建自定义窗口小部件的实例createWidget()函数,用合适的亲代部件。插件必须构造并返回一个自定义窗口小部件的实例与指定的父控件。

在类的实现,你必须记住你的自定义的widget插件导出到Qt Designer使用Q_EXPORT_PLUGIN2()宏。例如,如果一个所谓的库libcustomwidgetplugin.so( Unix)或libcustomwidget.dll(在Windows上)中包含一个称为widget类MyCustomWidget,我们可以通过添加下面的行到包含插件实现文件导出:

  1. Q_EXPORT_PLUGIN2(customwidgetplugin, MyCustomWidget)

这个宏可以确保Qt Designer可以访问和构建自定义部件。如果没有这个宏,是没有办法的Qt Designer使用它。

当实现一个自定义的widget插件,你把它做成一个单独的库。如果你想包括几个自定义的widget插件在同一个库中,你必须在另外的子类QDesignerCustomWidgetCollectionInterface

Warning:如果您的自定义窗口小部件插件包含QVariant性能,要知道,只有以下types支持:

对于使用QDesignerCustomWidgetInterface类的完整示例,请参见Custom Widget Example。该示例显示了如何创建一个自定义的widget插件Qt Designer


Method Documentation

  1. QDesignerCustomWidgetInterface.__init__ (self)
  1. QDesignerCustomWidgetInterface.__init__ (self, QDesignerCustomWidgetInterface)
  1. QString QDesignerCustomWidgetInterface.codeTemplate (self)

此功能保留供将来使用Qt Designer

  1. QWidget QDesignerCustomWidgetInterface.createWidget (self, QWidget parent)

[

这种方法是抽象的,应在任何子类中重新实现。

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

返回自定义窗口小部件的一个新实例,用给定的parent

  1. QString QDesignerCustomWidgetInterface.domXml (self)

返回用于描述自定义窗口小部件的属性到XMLQt Designer

  1. QString QDesignerCustomWidgetInterface.group (self)

这种方法是抽象的,应在任何子类中重新实现。

返回到自定义窗口小部件所属的组的名称。

](qwidget.html)

  1. QIcon QDesignerCustomWidgetInterface.icon (self)

[

这种方法是抽象的,应在任何子类中重新实现。

返回用于表示在自定义插件的图标Qt Designer的小工具盒。

  1. QString QDesignerCustomWidgetInterface.includeFile (self)

这种方法是抽象的,应在任何子类中重新实现。

]($docs-qicon.html)

返回的路径,包含文件uic创建自定义窗口小部件代码时使用。

  1. QDesignerCustomWidgetInterface.initialize (self, QDesignerFormEditorInterface core)

初始化部件具有指定用途formEditor接口。

See also isInitialized( ) 。

  1. bool QDesignerCustomWidgetInterface.isContainer (self)

这种方法是抽象的,应在任何子类中重新实现。

返回True如果自定义部件的目的是作为一个容器,否则返回False 。

大多数自定义窗体并不用来装其他部件,所以这个功能的实现将返回False ,但自定义容器将返回True ,以确保他们正确的行为Qt Designer

  1. bool QDesignerCustomWidgetInterface.isInitialized (self)

返回True如果控件已被初始化,否则返回False 。

See also initialize( ) 。

  1. QString QDesignerCustomWidgetInterface.name (self)

这种方法是抽象的,应在任何子类中重新实现。

返回由该接口提供的自定义窗口小部件的类名。

返回的名称must是相同的用于自定义插件的类名。

  1. QString QDesignerCustomWidgetInterface.toolTip (self)

这种方法是抽象的,应在任何子类中重新实现。

返回可使用的窗口小部件的简短说明Qt Designer在工具提示。

  1. QString QDesignerCustomWidgetInterface.whatsThis (self)

这种方法是抽象的,应在任何子类中重新实现。

返回可使用的窗口小部件的描述Qt Designer在“这是什么? ”帮助小部件。