PDA

View Full Version : No QCalendarWidget in designer? 4.2.0-tp1



Spockmeat
8th August 2006, 15:41
I just grabbed the 4.2.0 technology preview, and I was looking for that new QCalendarWidget in designer, but it doesn't seem to be there. Is this only accessible via code? Or is that something that will be added to the designer later?

jacek
8th August 2006, 18:06
Probably Qt Designer just wasn't updated. You can always create a plugin yourself.

Spockmeat
9th August 2006, 18:13
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


calendarplugin.h

#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



calendarplugin.cpp


#include "calendarplugin.h"
#include <QtPlugin>
#include <QCalendarWidget>

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

void CalendarPlugin::initialize(QDesignerFormEditorInte rface * /* 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)