将自定义的widget放到Qt Designer中

版权声明

请尊重原创作品。转载请保持文章完整性,并以超链接形式注明原始作者“tingsking18”和主站点地址,方便其他朋友提问和指正。

 

将上篇文章写的PushButton放到Qt Designer中:

PushButtonplugin.h

#include <QDesignerCustomWidgetInterface> class PushButtonPlugin:public QObject, public QDesignerCustomWidgetInterface { Q_OBJECT Q_INTERFACES(QDesignerCustomWidgetInterface) public: PushButtonPlugin(QObject *parent = 0); QString name() const; QString includeFile() const; QString group() const; QIcon icon() const; QString toolTip() const; QString whatsThis() const; bool isContainer() const; QWidget* createWidget(QWidget *parent); };

PushButtonplugin.cpp

#include "PushButtonplugin.h" #include "PushButton.h" #include <QtPlugin> PushButtonPlugin::PushButtonPlugin(QObject *parent) : QObject(parent) { } QString PushButtonPlugin::name() const { return "PushButton"; } QString PushButtonPlugin::includeFile() const { return "PushButton.h"; } QString PushButtonPlugin::group() const { return tr("Buttons"); } QIcon PushButtonPlugin::icon() const { return QIcon(":/images/bp_btn3.png"); } QString PushButtonPlugin::toolTip() const { return tr("An PushButton widget"); } QString PushButtonPlugin::whatsThis() const { return tr("This widget is PushButton widget"); } bool PushButtonPlugin::isContainer() const { return false; } QWidget* PushButtonPlugin::createWidget(QWidget *parent) { return new PushButton("PushButton",parent); } Q_EXPORT_PLUGIN2(PushButtonplugin, PushButtonPlugin)

PushButtonplugin.pro

QT += qt3support
TEMPLATE        = lib
CONFIG         += designer plugin release
HEADERS         = mPushButton.h /
                  mPushButtonplugin.h
SOURCES         = mPushButtonplugin.cpp
RESOURCES       = clicklabel.qrc
DESTDIR         = $(QTDIR)/plugins/designer  

你可能感兴趣的:(object,qt)