サブQtデザイナーにカスタムウィンドウコンポーネントを統合

6268 ワード

改良法(promotion):
同様の内蔵Qtウィンドウコンポーネントを選択することで
プラグイン法(plugin):
iconeditorplugin.h
#ifndef ICONEDITORPLUGIN_H

#define ICONEDITORPLUGIN_H



#include <QDesignerCustomWidgetInterface>



class IconEditorPlugin : public QObject,

                         public QDesignerCustomWidgetInterface

{

    Q_OBJECT

    Q_INTERFACES(QDesignerCustomWidgetInterface)   // Q_INTERFACES() moc::  QDesignerCustomWidgetInterface      

public:

    IconEditorPlugin(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);

};



#endif

iconeditorplugin.cpp
#include <QtPlugin>



#include "../iconeditor/iconeditor.h"

#include "iconeditorplugin.h"



IconEditorPlugin::IconEditorPlugin(QObject *parent)

    : QObject(parent)

{

}



QString IconEditorPlugin::name() const

{

    return "IconEditor";

}



QString IconEditorPlugin::includeFile() const

{

    return "iconeditor.h";

}



QString IconEditorPlugin::group() const

{

    return tr("Image Manipulation Widgets");

}



QIcon IconEditorPlugin::icon() const

{

    return QIcon(":/images/iconeditor.png");

}



QString IconEditorPlugin::toolTip() const

{

    return tr("An icon editor widget");

}



QString IconEditorPlugin::whatsThis() const

{

    return tr("This widget is presented in Chapter 5 of <i>C++ GUI "

              "Programming with Qt 4</i> as an example of a custom Qt "

              "widget.");

}



bool IconEditorPlugin::isContainer() const

{

    return false;

}



QWidget *IconEditorPlugin::createWidget(QWidget *parent)

{

    return new IconEditor(parent);

}



Q_EXPORT_PLUGIN2(iconeditorplugin, IconEditorPlugin)  // , Qt , , 

iconeditorplugin.pro
TEMPLATE      = lib

CONFIG       += designer plugin release

HEADERS       = ../iconeditor/iconeditor.h \

                iconeditorplugin.h

SOURCES       = ../iconeditor/iconeditor.cpp \

                iconeditorplugin.cpp

RESOURCES     = iconeditorplugin.qrc

DESTDIR       = $$[QT_INSTALL_PLUGINS]/designer  //QT_INSTALL_PLUGINS Qt plugins