Sorry it took so long to reply. I'm not sure what you mean about dllexport and dllimport (I found that they are macros, but beyond that I dont know what they do).
Here's the code. There is a "clickarea" header and cpp file, and a "clickareaplugin" header and cpp file.
//ClickArea.h
#ifndef CLICKAREA_H
#define CLICKAREA_H
#include <QtGui/QAbstractButton>
#include <QtDesigner/QDesignerExportWidget>
QT_BEGIN_HEADER
QT_MODULE(Gui)
{
Q_OBJECT
Q_PROPERTY(int Index READ getIndex WRITE setIndex)
public:
int getIndex() const;
protected:
public Q_SLOTS:
void setIndex(const int);
signals:
void pressed();
void released();
void clicked(int);
private:
int Index;
};
QT_END_HEADER
#endif
//ClickArea.h
#ifndef CLICKAREA_H
#define CLICKAREA_H
#include <QtGui/QAbstractButton>
#include <QtDesigner/QDesignerExportWidget>
QT_BEGIN_HEADER
QT_MODULE(Gui)
class QDESIGNER_WIDGET_EXPORT ClickArea : public QAbstractButton
{
Q_OBJECT
Q_PROPERTY(int Index READ getIndex WRITE setIndex)
public:
ClickArea(QWidget *parent = 0);
int getIndex() const;
protected:
void paintEvent(QPaintEvent *e);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
public Q_SLOTS:
void setIndex(const int);
signals:
void pressed();
void released();
void clicked(int);
private:
int Index;
};
QT_END_HEADER
#endif
To copy to clipboard, switch view to plain text mode
//ClickArea.cpp
#include "clickarea.h"
#include <QtGui/QtGui.h>
{
}
{
emit pressed();
}
{
emit released();
emit clicked(Index);
}
{
}
void ClickArea::setIndex(const int value)
{
Index = value;
}
int ClickArea::getIndex() const
{
return Index;
}
//ClickArea.cpp
#include "clickarea.h"
#include <QtGui/QtGui.h>
ClickArea::ClickArea(QWidget *parent): QAbstractButton(parent)
{
}
void ClickArea::mousePressEvent(QMouseEvent *event)
{
emit pressed();
}
void ClickArea::mouseReleaseEvent(QMouseEvent *event)
{
emit released();
emit clicked(Index);
}
void ClickArea::paintEvent(QPaintEvent *e)
{
}
void ClickArea::setIndex(const int value)
{
Index = value;
}
int ClickArea::getIndex() const
{
return Index;
}
To copy to clipboard, switch view to plain text mode
//ClickAreaPlugin.h
#ifndef CLICKAREAPLUGIN_H
#define CLICKAREAPLUGIN_H
#include <QtDesigner/QDesignerCustomWidgetInterface>
{
Q_OBJECT
public:
ClickAreaPlugin
(QObject *parent
= 0);
bool isContainer() const;
bool isInitialized() const;
private:
bool initialized;
};
#endif
//ClickAreaPlugin.h
#ifndef CLICKAREAPLUGIN_H
#define CLICKAREAPLUGIN_H
#include <QtDesigner/QDesignerCustomWidgetInterface>
class ClickAreaPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
ClickAreaPlugin(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
To copy to clipboard, switch view to plain text mode
//ClickAreaPlugin.cpp
#include "clickareaplugin.h"
#include "clickarea.h"
#include <QtPlugin>
ClickAreaPlugin
::ClickAreaPlugin(QObject *parent
){
initialized = false;
}
{
if (initialized)
return;
initialized = true;
}
bool ClickAreaPlugin::isInitialized() const
{
return initialized;
}
{
return new ClickArea(parent);
}
QString ClickAreaPlugin
::name() const {
return "ClickArea";
}
QString ClickAreaPlugin
::group() const {
return "Buttons";
}
QIcon ClickAreaPlugin
::icon() const {
}
QString ClickAreaPlugin
::toolTip() const {
return "";
}
QString ClickAreaPlugin
::whatsThis() const {
return "";
}
bool ClickAreaPlugin::isContainer() const
{
return false;
}
QString ClickAreaPlugin
::domXml() const {
return "<widget class=\"Click Area\" name=\"ClickArea\">\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"
"</widget>\n";
}
QString ClickAreaPlugin
::includeFile() const {
return "clickarea.h";
}
Q_EXPORT_PLUGIN2(clickareaplugin, ClickAreaPlugin)
//ClickAreaPlugin.cpp
#include "clickareaplugin.h"
#include "clickarea.h"
#include <QtPlugin>
ClickAreaPlugin::ClickAreaPlugin(QObject *parent)
: QObject(parent)
{
initialized = false;
}
void ClickAreaPlugin::initialize(QDesignerFormEditorInterface *)
{
if (initialized)
return;
initialized = true;
}
bool ClickAreaPlugin::isInitialized() const
{
return initialized;
}
QWidget *ClickAreaPlugin::createWidget(QWidget *parent)
{
return new ClickArea(parent);
}
QString ClickAreaPlugin::name() const
{
return "ClickArea";
}
QString ClickAreaPlugin::group() const
{
return "Buttons";
}
QIcon ClickAreaPlugin::icon() const
{
return QIcon();
}
QString ClickAreaPlugin::toolTip() const
{
return "";
}
QString ClickAreaPlugin::whatsThis() const
{
return "";
}
bool ClickAreaPlugin::isContainer() const
{
return false;
}
QString ClickAreaPlugin::domXml() const
{
return "<widget class=\"Click Area\" name=\"ClickArea\">\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"
"</widget>\n";
}
QString ClickAreaPlugin::includeFile() const
{
return "clickarea.h";
}
Q_EXPORT_PLUGIN2(clickareaplugin, ClickAreaPlugin)
To copy to clipboard, switch view to plain text mode
Bookmarks