版權(quán)聲明
請(qǐng)尊重原創(chuàng)作品。轉(zhuǎn)載請(qǐng)保持文章完整性,并以超鏈接形式注明原始作者“tingsking18”和主站點(diǎn)地址,方便其他朋友提問(wèn)和指正。
將上篇文章寫(xiě)的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