qt-interest@trolltech.com
[Top] [All Lists]

Re: Custom Widget Plugin

Subject: Re: Custom Widget Plugin
From: Minh Tran
Date: Fri, 09 Jun 2006 09:04:46 +1000
Hello

It looks about right. Which platform is this? I've only ever done it on Linux and I found that the make is broken for plugins for "debug_and_release" configs (I reported the bug a while back and according to task tracker, it isn't fixed ID 101884). I'd imagine it would be broken for other platforms as well but I can't be certain.

To get around this, make sure you do "make all" or change debug_and_release to release. This will ensure the release gets built. Note that designer will only look at the release version, not the debug one.

Now to ensure you put the result plugin in the correct directory. I put it in "QT_INSTALL_PATH/plugins/designer" (sorry this is off the top of my head, not 100%). You'll find the rest of the designer plugins in here as well. If everything else is right with the plugins, it should now appear in designer.

Minh

Josinei Silva wrote:
Iá trying to create a custom widget plugin to use with Qt Designer following Qt documentation instructions.

I can compile and install my plugin, but when i started designer, my plugin don t appears and there's no error message when loading desiger.

Someone can send me a little example that works?

Thanks

Josinei

These are my pluginÅ files:

plugins.pro:
---------------------------------------------------------------------------------------------------------------
HEADERS     = /home/Desenvolvimento/Lib/Include/analogclock.h \
              /home/Desenvolvimento/Lib/Include/customwidgetplugin.h
SOURCES     = analogclock.cpp \
              customwidgetplugin.cpp
TARGET    = MyPlugin
target.path=$$[QT_INSTALL_PLUGINS]/designer
CONFIG      += designer plugin debug_and_release
TEMPLATE     = lib
INSTALLS    += target
INCLUDEPATH += /home/Desenvolvimento/Lib/Include
INCLUDEPATH += /home/Desenvolvimento/Lib/Include/tmp
---------------------------------------------------------------------------------------------------------


analogclock.cpp:
--------------------------------------------------------------------------------------------------------------------
#include <QtGui>

#include "analogclock.h"

AnalogClock::AnalogClock(QWidget *parent)
    : QWidget(parent)
{
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    timer->start(1000);

    setWindowTitle(tr("Analog Clock"));
    resize(200, 200);
}

void AnalogClock::paintEvent(QPaintEvent *)
{
    static const QPoint hourHand[3] = {
        QPoint(7, 8),
        QPoint(-7, 8),
        QPoint(0, -40)
    };
    static const QPoint minuteHand[3] = {
        QPoint(7, 8),
        QPoint(-7, 8),
        QPoint(0, -70)
    };

    QColor hourColor(127, 0, 127);
    QColor minuteColor(0, 127, 127, 191);

    int side = qMin(width(), height());
    QTime time = QTime::currentTime();

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.translate(width() / 2, height() / 2);
    painter.scale(side / 200.0, side / 200.0);

    painter.setPen(Qt::NoPen);
    painter.setBrush(hourColor);

    painter.save();
    painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
    painter.drawConvexPolygon(hourHand, 3);
    painter.restore();

    painter.setPen(hourColor);

    for (int i = 0; i < 12; ++i) {
        painter.drawLine(88, 0, 96, 0);
        painter.rotate(30.0);
    }

    painter.setPen(Qt::NoPen);
    painter.setBrush(minuteColor);

    painter.save();
    painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
    painter.drawConvexPolygon(minuteHand, 3);
    painter.restore();

    painter.setPen(minuteColor);

    for (int j = 0; j < 60; ++j) {
        if ((j % 5) != 0)
            painter.drawLine(92, 0, 96, 0);
        painter.rotate(6.0);
    }
}
-------------------------------------------------------------------------------------------------------

analogclock.h:
-----------------------------------------------------------------------------------------------------------
#ifndef ANALOGCLOCK_H
#define ANALOGCLOCK_H

#include <QWidget>
#include <QtDesigner/QDesignerExportWidget>

class QDESIGNER_WIDGET_EXPORT AnalogClock : public QWidget
{
    Q_OBJECT

public:
    AnalogClock(QWidget *parent = 0);

protected:
    void paintEvent(QPaintEvent *event);
};

#endif
-------------------------------------------------------------------------------------------------------------

customwidgetpluing.cpp:
-----------------------------------------------------------------------------------------------------------
#include "analogclock.h"
#include "customwidgetplugin.h"

#include <QtPlugin>

AnalogClockPlugin::AnalogClockPlugin(QObject *parent)
        : QObject(parent)
{
        initialized = false;
}

void AnalogClockPlugin::initialize(QDesignerFormEditorInterface * /* core */)
{
        if (initialized)
            return;

        initialized = true;
}

bool AnalogClockPlugin::isInitialized() const
{
        return initialized;
}

QWidget *AnalogClockPlugin::createWidget(QWidget *parent)
{
        return new AnalogClock(parent);
}

QString AnalogClockPlugin::name() const
{
        return "AnalogClock";
}

QString AnalogClockPlugin::group() const
{
return "Display Widgets [Examples]";
}

QIcon AnalogClockPlugin::icon() const
{
        return QIcon();
}

QString AnalogClockPlugin::toolTip() const
{
        return "";
}

QString AnalogClockPlugin::whatsThis() const
{
        return "";
}

bool AnalogClockPlugin::isContainer() const
{
        return false;
}

QString AnalogClockPlugin::domXml() const
{
        return "<widget class=\"AnalogClock\" name=\"analogClock\">\n"
               " <property name=\"geometry\">\n"
               "  <rect>\n"
               "   <x>0</x>\n"
               "   <y>0</y>\n"
               "   <width>100</width>\n"
               "   <height>100</height>\n"
               "  </rect>\n"
               " </property>\n"
               " <property name=\"toolTip\" >\n"
               "  <string>The current time</string>\n"
               " </property>\n"
               " <property name=\"whatsThis\" >\n"
               "  <string>The analog clock widget displays "
               "the current time.</string>\n"
               " </property>\n"
               "</widget>\n";
}

QString AnalogClockPlugin::includeFile() const
{
        return "analogclock.h";
}

Q_EXPORT_PLUGIN2(customwidgetplugin, AnalogClockPlugin)
---------------------------------------------------------------------------------------------------------------

customwidgetplugin.h:
----------------------------------------------------------------------------------------------------------------
#ifndef CUSTOMWIDGETPLUGIN_H
#define CUSTOMWIDGETPLUGIN_H

#include <QDesignerCustomWidgetInterface>

class AnalogClockPlugin : public QObject, public QDesignerCustomWidgetInterface
{
        Q_OBJECT
        Q_INTERFACES(QDesignerCustomWidgetInterface)

    public:
        AnalogClockPlugin(QObject *parent = 0);

        bool isContainer() const;
        bool isInitialized() const;
        QIcon icon() const;
        QString domXml() const;
        QString group() const;
        QString includeFile() const;
        QString name() const;
        QString toolTip() const;
        QString whatsThis() const;
        QWidget *createWidget(QWidget *parent);
        void initialize(QDesignerFormEditorInterface *core);

    private:
        bool initialized;
};

#endif
-------------------------------------------------------------------------------------------------------------

                
_______________________________________________________ Abra sua conta no Yahoo! Mail: 1GB de espaïo, alertas de e-mail no celular e anti-spam realmente eficaz. http://mail.yahoo.com.br/

--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/



--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>