Indeed. I've never made a plug in before but it seemed fairly easy. Here's the code for it if anyone cares:
calendarplugin.pro
CONFIG += designer plugin debug_and_release
TEMPLATE = lib
HEADERS = calendarplugin.h
SOURCES = calendarplugin.cpp
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
CONFIG += designer plugin debug_and_release
TEMPLATE = lib
HEADERS = calendarplugin.h
SOURCES = calendarplugin.cpp
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
To copy to clipboard, switch view to plain text mode
calendarplugin.h
#ifndef CALENDARPLUGIN_H
#define CALENDARPLUGIN_H
#include <QDesignerCustomWidgetInterface>
{
Q_OBJECT
public:
CalendarPlugin
(QObject *parent
= 0);
bool isContainer() const;
bool isInitialized() const;
private:
bool initialized;
};
#endif
#ifndef CALENDARPLUGIN_H
#define CALENDARPLUGIN_H
#include <QDesignerCustomWidgetInterface>
class CalendarPlugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
CalendarPlugin(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
calendarplugin.cpp
#include "calendarplugin.h"
#include <QtPlugin>
#include <QCalendarWidget>
CalendarPlugin
::CalendarPlugin(QObject *parent
){
initialized = false;
}
{
if (initialized)
return;
initialized = true;
}
bool CalendarPlugin::isInitialized() const
{
return initialized;
}
{
}
QString CalendarPlugin
::name() const {
return "QCalendar";
}
QString CalendarPlugin
::group() const {
return "Input Widgets";
}
QIcon CalendarPlugin
::icon() const {
}
QString CalendarPlugin
::toolTip() const {
return "";
}
QString CalendarPlugin
::whatsThis() const {
return "";
}
bool CalendarPlugin::isContainer() const
{
return false;
}
QString CalendarPlugin
::domXml() const {
return "<widget class=\"QCalendarWidget\" name=\"calendarWidget\">\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>Show dates and pick one</string>\n"
" </property>\n"
" <property name=\"whatsThis\" >\n"
" <string>The calendar widget allows "
"a user to pick the current date.</string>\n"
" </property>\n"
"</widget>\n";
}
QString CalendarPlugin
::includeFile() const {
return "qcalendarwidget.h";
}
Q_EXPORT_PLUGIN2(calendarplugin, CalendarPlugin)
#include "calendarplugin.h"
#include <QtPlugin>
#include <QCalendarWidget>
CalendarPlugin::CalendarPlugin(QObject *parent)
: QObject(parent)
{
initialized = false;
}
void CalendarPlugin::initialize(QDesignerFormEditorInterface * /* core */)
{
if (initialized)
return;
initialized = true;
}
bool CalendarPlugin::isInitialized() const
{
return initialized;
}
QWidget *CalendarPlugin::createWidget(QWidget *parent)
{
return new QCalendarWidget(parent);
}
QString CalendarPlugin::name() const
{
return "QCalendar";
}
QString CalendarPlugin::group() const
{
return "Input Widgets";
}
QIcon CalendarPlugin::icon() const
{
return QIcon();
}
QString CalendarPlugin::toolTip() const
{
return "";
}
QString CalendarPlugin::whatsThis() const
{
return "";
}
bool CalendarPlugin::isContainer() const
{
return false;
}
QString CalendarPlugin::domXml() const
{
return "<widget class=\"QCalendarWidget\" name=\"calendarWidget\">\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>Show dates and pick one</string>\n"
" </property>\n"
" <property name=\"whatsThis\" >\n"
" <string>The calendar widget allows "
"a user to pick the current date.</string>\n"
" </property>\n"
"</widget>\n";
}
QString CalendarPlugin::includeFile() const
{
return "qcalendarwidget.h";
}
Q_EXPORT_PLUGIN2(calendarplugin, CalendarPlugin)
To copy to clipboard, switch view to plain text mode
Bookmarks