If I implement my own property sheet extension so in this case i will miss the default property editor given by the widget or the qt designer . But i want to use the both property editor the one provided by the QT designer and other which is written by me So is there any way
@Ashutosh2k1
I had to solve the same issue. Here is what i came up with after several experiments.
First declare a custom property sheet factory:
{
public:
protected:
private:
mutable bool mCreateExtensionCalled;
};
class CCustomWidgetPropertySheetFactory : public QExtensionFactory
{
typedef QExtensionFactory inherited;
public:
CCustomWidgetPropertySheetFactory(QExtensionManager * apParent);
protected:
virtual QObject * createExtension(QObject * apObject, const QString & arIId, QObject * apParent) const;
private:
QExtensionManager * mpExtensionManager;
mutable bool mCreateExtensionCalled;
};
To copy to clipboard, switch view to plain text mode
...then add the implementation of the factory...
CCustomWidgetPropertySheetFactory
::CCustomWidgetPropertySheetFactory(QExtensionManager * apParent
) : inherited(apParent)
, mpExtensionManager(apParent)
, mCreateExtensionCalled(false)
{}
QObject * CCustomWidgetPropertySheetFactory
::createExtension(QObject * apObject,
const QString & arIId,
QObject /* QExtensionFactory */ * apParent
) const {
if (!mCreateExtensionCalled)
{
// note: setting flag to avoid infinite loop caused by later usage of qt_extension<>
mCreateExtensionCalled = true;
{
CCustomWidget * lCustomWidget(qobject_cast<CCustomWidget *>(apObject));
if (lCustomWidget)
{
QDesignerPropertySheetExtension * lDefaultPropertySheetExtensionImplementor
(qt_extension<QDesignerPropertySheetExtension
*>
(mpExtensionManager, apObject
));
if (lDefaultPropertySheetExtensionImplementor)
{
lResult = new CCustomWidgetPropertySheetExtension(apParent, *lDefaultPropertySheetExtensionImplementor);
}
}
}
mCreateExtensionCalled = false;
}
return lResult;
}
CCustomWidgetPropertySheetFactory::CCustomWidgetPropertySheetFactory(QExtensionManager * apParent)
: inherited(apParent)
, mpExtensionManager(apParent)
, mCreateExtensionCalled(false)
{}
QObject * CCustomWidgetPropertySheetFactory::createExtension(QObject * apObject, const QString & arIId, QObject /* QExtensionFactory */ * apParent) const
{
QObject * lResult(0);
if (!mCreateExtensionCalled)
{
// note: setting flag to avoid infinite loop caused by later usage of qt_extension<>
mCreateExtensionCalled = true;
if (arIId == Q_TYPEID(QDesignerPropertySheetExtension))
{
CCustomWidget * lCustomWidget(qobject_cast<CCustomWidget *>(apObject));
if (lCustomWidget)
{
QDesignerPropertySheetExtension * lDefaultPropertySheetExtensionImplementor(qt_extension<QDesignerPropertySheetExtension *>(mpExtensionManager, apObject));
if (lDefaultPropertySheetExtensionImplementor)
{
lResult = new CCustomWidgetPropertySheetExtension(apParent, *lDefaultPropertySheetExtensionImplementor);
}
}
}
mCreateExtensionCalled = false;
}
return lResult;
}
To copy to clipboard, switch view to plain text mode
So far we created a custom property sheet and pass the default property sheet to it. Now declare the custom property sheet (i simplified the code for better understanding here):
{
Q_OBJECT
public:
CCustomWidgetPropertySheetExtension
(QObject * apParent,
virtual ~CCustomWidgetPropertySheetExtension();
virtual int count() const;
virtual int indexOf
(const QString &name
) const;
virtual QString propertyName
(int index
) const;
virtual QString propertyGroup
(int index
) const;
virtual bool isVisible(int index) const;
virtual QVariant property
(int index
) const;
...
private:
int mPropertyCount;
};
class CCustomWidgetPropertySheetExtension : public QObject, public QDesignerPropertySheetExtension
{
Q_OBJECT
Q_INTERFACES(QDesignerPropertySheetExtension)
public:
CCustomWidgetPropertySheetExtension(QObject * apParent,
QDesignerPropertySheetExtension & apDefaultPropertySheetExtension);
virtual ~CCustomWidgetPropertySheetExtension();
virtual int count() const;
virtual int indexOf(const QString &name) const;
virtual QString propertyName(int index) const;
virtual QString propertyGroup(int index) const;
virtual bool isVisible(int index) const;
virtual QVariant property(int index) const;
...
private:
QDesignerPropertySheetExtension & mpDefaultPropertySheetExtension;
int mPropertyCount;
};
To copy to clipboard, switch view to plain text mode
...and add the implementation of the custom property sheet...
CCustomWidgetPropertySheetExtension
::CCustomWidgetPropertySheetExtension(QObject * apParent,
, mpDefaultPropertySheetExtension(apDefaultPropertySheetExtension)
, mPropertyCount(mpDefaultPropertySheetExtension.count() + 1)
{}
CCustomWidgetPropertySheetExtension::~CCustomWidgetPropertySheetExtension()
{}
...
int CCustomWidgetPropertySheetExtension::count() const
{
return mPropertyCount;
}
int CCustomWidgetPropertySheetExtension::indexOf( const QString& name ) const
{
if (name == "MyCustomProperty")
return mPropertyCount - 1;
else
return mpDefaultPropertySheetExtension.indexOf(name);
}
QString CCustomWidgetPropertySheetExtension
::propertyName( int index
) const {
if (index == mPropertyCount - 1)
return "MyCustomProperty";
else
return mpDefaultPropertySheetExtension.propertyName(index);
}
QString CCustomWidgetPropertySheetExtension
::propertyGroup( int index
) const {
if (index == mPropertyCount - 1)
return "MyCustomPropertyGroup";
else
return mpDefaultPropertySheetExtension.propertyGroup(index);
}
bool CCustomWidgetPropertySheetExtension::isVisible( int index ) const
{
if (index == mPropertyCount - 1)
return true;
else
return mpDefaultPropertySheetExtension.isVisible(index);
}
QVariant CCustomWidgetPropertySheetExtension
::property( int index
) const {
if (index == mPropertyCount - 1)
else
return mpDefaultPropertySheetExtension.property(index);
}
CCustomWidgetPropertySheetExtension::CCustomWidgetPropertySheetExtension(QObject * apParent,
QDesignerPropertySheetExtension & apDefaultPropertySheetExtension)
: QObject(apParent)
, QDesignerPropertySheetExtension()
, mpDefaultPropertySheetExtension(apDefaultPropertySheetExtension)
, mPropertyCount(mpDefaultPropertySheetExtension.count() + 1)
{}
CCustomWidgetPropertySheetExtension::~CCustomWidgetPropertySheetExtension()
{}
...
int CCustomWidgetPropertySheetExtension::count() const
{
return mPropertyCount;
}
int CCustomWidgetPropertySheetExtension::indexOf( const QString& name ) const
{
if (name == "MyCustomProperty")
return mPropertyCount - 1;
else
return mpDefaultPropertySheetExtension.indexOf(name);
}
QString CCustomWidgetPropertySheetExtension::propertyName( int index ) const
{
if (index == mPropertyCount - 1)
return "MyCustomProperty";
else
return mpDefaultPropertySheetExtension.propertyName(index);
}
QString CCustomWidgetPropertySheetExtension::propertyGroup( int index ) const
{
if (index == mPropertyCount - 1)
return "MyCustomPropertyGroup";
else
return mpDefaultPropertySheetExtension.propertyGroup(index);
}
bool CCustomWidgetPropertySheetExtension::isVisible( int index ) const
{
if (index == mPropertyCount - 1)
return true;
else
return mpDefaultPropertySheetExtension.isVisible(index);
}
QVariant CCustomWidgetPropertySheetExtension::property( int index ) const
{
if (index == mPropertyCount - 1)
return QVariant(true);
else
return mpDefaultPropertySheetExtension.property(index);
}
To copy to clipboard, switch view to plain text mode
Compile and you will see the custom property "MyCustomProperty" displayed in the designer in the property group "MyCustomPropertyGroup" for the widget "CCustomWidget".
Hope this helps.
So lonG
Daniel
Bookmarks