SamFredericks
4th May 2011, 16:14
Hello,
I wrote my own ButtonPlugin for the QtDesigner. In addition I implemented for this ButtonPlugin an own ButtonPropertySheetExtension.
I used the template from QtCreator for creating QtDesigner-Plugins and only changed the following function in ButtonPlugin.cpp:
void ButtonPlugin::initialize(QDesignerFormEditorInterf ace * core)
{
if (m_initialized)
return;
QExtensionManager *manager = core->extensionManager();
Q_ASSERT(manager != 0);
manager->registerExtensions(new ButtonPropertyFactory(manager), Q_TYPEID(QDesignerPropertySheetExtension));
m_initialized = true;
}
In addition I created ButtonPropertySheetExtension.h:
#include <QObject>
#include <QMap>
#include <QString>
#include <QDesignerPropertySheetExtension>
#include <QExtensionFactory>
#include "button.h"
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ButtonPropertyFactory
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
class ButtonPropertyFactory : public QExtensionFactory
{
Q_OBJECT
public:
ButtonPropertyFactory(QExtensionManager *parent = 0);
protected:
QObject *createExtension(QObject *object, const QString &iid, QObject *parent) const;
};
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ButtonPropertySheetExtension
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
class ButtonPropertySheetExtension : public QObject, QDesignerPropertySheetExtension
{
Q_OBJECT
Q_INTERFACES(QDesignerPropertySheetExtension)
public:
ButtonPropertySheetExtension(Button* p, QObject *parent);
int count (void) const;
bool hasReset ( int index ) const;
int indexOf ( const QString & name ) const;
bool isAttribute ( int index ) const;
bool isChanged ( int index ) const;
bool isVisible ( int index ) const;
QVariant property ( int index ) const;
QString propertyGroup ( int index ) const;
QString propertyName ( int index ) const;
bool reset ( int index );
void setAttribute ( int index, bool attribute );
void setChanged ( int index, bool changed );
void setProperty ( int index, const QVariant & value );
void setPropertyGroup ( int index, const QString & group );
void setVisible ( int index, bool visible );
protected:
Button* _powner;
const QMetaObject* _p_metaobject;
QMap<int, QString> _PropertyGroups;
};
And I created ButtonPropertySheetExtension.cpp:
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ButtonPropertyFactory
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
ButtonPropertyFactory::ButtonPropertyFactory(QExte nsionManager *parent)
: QExtensionFactory(parent)
{
}
QObject *ButtonPropertyFactory::createExtension(QObject *object,
const QString &iid,
QObject *parent) const
{
if (iid != Q_TYPEID(QDesignerPropertySheetExtension))
return 0;
if (Button* pbutton = qobject_cast<Button*>(object))
return new ButtonPropertySheetExtension(pbutton, parent);
return 0;
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ButtonPropertySheetExtension
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
ButtonPropertySheetExtension::ButtonPropertySheetE xtension(Button* p, QObject *parent) :
QObject(parent),
_powner(p),
_p_metaobject(_powner->metaObject()),
_PropertyGroups()
{
const int i_object_index = indexOf("objectName");
setPropertyGroup(i_object_index, "QObject");
const int i_widget_index = indexOf("modal");
setPropertyGroup(i_widget_index, "QWidget");
const int i_abstractbutton_index = indexOf("text");
setPropertyGroup(i_abstractbutton_index, "QAbstractButton");
const int i_pushbutton_index = indexOf("autoDefault");
setPropertyGroup(i_pushbutton_index, "QPushButton");
}
int ButtonPropertySheetExtension::count () const
{
return _p_metaobject->propertyCount();
}
bool ButtonPropertySheetExtension::hasReset ( int index ) const
{
return _p_metaobject->property(index).isResettable();
}
int ButtonPropertySheetExtension::indexOf ( const QString & name ) const
{
return _p_metaobject->indexOfProperty( name.toLatin1().constData() );
}
bool ButtonPropertySheetExtension::isAttribute ( int index ) const
{
Q_UNUSED(index)
return false;
}
bool ButtonPropertySheetExtension::isChanged ( int index ) const
{
Q_UNUSED(index)
return false;
}
bool ButtonPropertySheetExtension::isVisible ( int index ) const
{
Q_UNUSED(index)
return true;
}
QVariant ButtonPropertySheetExtension::property ( int index ) const
{
return _p_metaobject->property(index).read(_powner);
}
QString ButtonPropertySheetExtension::propertyGroup ( int index ) const
{
QMap<int, QString>::const_iterator it = _PropertyGroups.begin();
if (index > 0){
while (it.key() <= index){
it++;
}
it--;
}
return it.value();
}
QString ButtonPropertySheetExtension::propertyName ( int index ) const
{
return QString(_p_metaobject->property(index).name());
}
bool ButtonPropertySheetExtension::reset ( int index )
{
return _p_metaobject->property(index).reset(_powner);
}
void ButtonPropertySheetExtension::setAttribute ( int index, bool attribute )
{
Q_UNUSED(index)
Q_UNUSED(attribute)
}
void ButtonPropertySheetExtension::setChanged ( int index, bool changed )
{
Q_UNUSED(index)
Q_UNUSED(changed)
}
void ButtonPropertySheetExtension::setProperty ( int index, const QVariant & value )
{
QMetaProperty metaproperty = _p_metaobject->property(index);
metaproperty.write(_powner, value);
}
void ButtonPropertySheetExtension::setPropertyGroup ( int index, const QString & group )
{
_PropertyGroups.insert(index, group);
}
void ButtonPropertySheetExtension::setVisible ( int index, bool visible )
{
Q_UNUSED(index)
Q_UNUSED(visible)
}
So my question, why is the attribute "icon" of QAbstractButton not shown in QtDesigner?
The same behaviour occurs by implementing - for example LabelPlugin (QLabel). Here the "pixmap" Property will be not shown.
I would be very happy aboput any good advice.
Thanks
I wrote my own ButtonPlugin for the QtDesigner. In addition I implemented for this ButtonPlugin an own ButtonPropertySheetExtension.
I used the template from QtCreator for creating QtDesigner-Plugins and only changed the following function in ButtonPlugin.cpp:
void ButtonPlugin::initialize(QDesignerFormEditorInterf ace * core)
{
if (m_initialized)
return;
QExtensionManager *manager = core->extensionManager();
Q_ASSERT(manager != 0);
manager->registerExtensions(new ButtonPropertyFactory(manager), Q_TYPEID(QDesignerPropertySheetExtension));
m_initialized = true;
}
In addition I created ButtonPropertySheetExtension.h:
#include <QObject>
#include <QMap>
#include <QString>
#include <QDesignerPropertySheetExtension>
#include <QExtensionFactory>
#include "button.h"
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ButtonPropertyFactory
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
class ButtonPropertyFactory : public QExtensionFactory
{
Q_OBJECT
public:
ButtonPropertyFactory(QExtensionManager *parent = 0);
protected:
QObject *createExtension(QObject *object, const QString &iid, QObject *parent) const;
};
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ButtonPropertySheetExtension
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
class ButtonPropertySheetExtension : public QObject, QDesignerPropertySheetExtension
{
Q_OBJECT
Q_INTERFACES(QDesignerPropertySheetExtension)
public:
ButtonPropertySheetExtension(Button* p, QObject *parent);
int count (void) const;
bool hasReset ( int index ) const;
int indexOf ( const QString & name ) const;
bool isAttribute ( int index ) const;
bool isChanged ( int index ) const;
bool isVisible ( int index ) const;
QVariant property ( int index ) const;
QString propertyGroup ( int index ) const;
QString propertyName ( int index ) const;
bool reset ( int index );
void setAttribute ( int index, bool attribute );
void setChanged ( int index, bool changed );
void setProperty ( int index, const QVariant & value );
void setPropertyGroup ( int index, const QString & group );
void setVisible ( int index, bool visible );
protected:
Button* _powner;
const QMetaObject* _p_metaobject;
QMap<int, QString> _PropertyGroups;
};
And I created ButtonPropertySheetExtension.cpp:
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ButtonPropertyFactory
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
ButtonPropertyFactory::ButtonPropertyFactory(QExte nsionManager *parent)
: QExtensionFactory(parent)
{
}
QObject *ButtonPropertyFactory::createExtension(QObject *object,
const QString &iid,
QObject *parent) const
{
if (iid != Q_TYPEID(QDesignerPropertySheetExtension))
return 0;
if (Button* pbutton = qobject_cast<Button*>(object))
return new ButtonPropertySheetExtension(pbutton, parent);
return 0;
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ButtonPropertySheetExtension
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
ButtonPropertySheetExtension::ButtonPropertySheetE xtension(Button* p, QObject *parent) :
QObject(parent),
_powner(p),
_p_metaobject(_powner->metaObject()),
_PropertyGroups()
{
const int i_object_index = indexOf("objectName");
setPropertyGroup(i_object_index, "QObject");
const int i_widget_index = indexOf("modal");
setPropertyGroup(i_widget_index, "QWidget");
const int i_abstractbutton_index = indexOf("text");
setPropertyGroup(i_abstractbutton_index, "QAbstractButton");
const int i_pushbutton_index = indexOf("autoDefault");
setPropertyGroup(i_pushbutton_index, "QPushButton");
}
int ButtonPropertySheetExtension::count () const
{
return _p_metaobject->propertyCount();
}
bool ButtonPropertySheetExtension::hasReset ( int index ) const
{
return _p_metaobject->property(index).isResettable();
}
int ButtonPropertySheetExtension::indexOf ( const QString & name ) const
{
return _p_metaobject->indexOfProperty( name.toLatin1().constData() );
}
bool ButtonPropertySheetExtension::isAttribute ( int index ) const
{
Q_UNUSED(index)
return false;
}
bool ButtonPropertySheetExtension::isChanged ( int index ) const
{
Q_UNUSED(index)
return false;
}
bool ButtonPropertySheetExtension::isVisible ( int index ) const
{
Q_UNUSED(index)
return true;
}
QVariant ButtonPropertySheetExtension::property ( int index ) const
{
return _p_metaobject->property(index).read(_powner);
}
QString ButtonPropertySheetExtension::propertyGroup ( int index ) const
{
QMap<int, QString>::const_iterator it = _PropertyGroups.begin();
if (index > 0){
while (it.key() <= index){
it++;
}
it--;
}
return it.value();
}
QString ButtonPropertySheetExtension::propertyName ( int index ) const
{
return QString(_p_metaobject->property(index).name());
}
bool ButtonPropertySheetExtension::reset ( int index )
{
return _p_metaobject->property(index).reset(_powner);
}
void ButtonPropertySheetExtension::setAttribute ( int index, bool attribute )
{
Q_UNUSED(index)
Q_UNUSED(attribute)
}
void ButtonPropertySheetExtension::setChanged ( int index, bool changed )
{
Q_UNUSED(index)
Q_UNUSED(changed)
}
void ButtonPropertySheetExtension::setProperty ( int index, const QVariant & value )
{
QMetaProperty metaproperty = _p_metaobject->property(index);
metaproperty.write(_powner, value);
}
void ButtonPropertySheetExtension::setPropertyGroup ( int index, const QString & group )
{
_PropertyGroups.insert(index, group);
}
void ButtonPropertySheetExtension::setVisible ( int index, bool visible )
{
Q_UNUSED(index)
Q_UNUSED(visible)
}
So my question, why is the attribute "icon" of QAbstractButton not shown in QtDesigner?
The same behaviour occurs by implementing - for example LabelPlugin (QLabel). Here the "pixmap" Property will be not shown.
I would be very happy aboput any good advice.
Thanks