Custom Property On Custom Widget
Hi All,
I need a very urget clarification .Can we show the Custom Property (Like of Struct where each type of struct may be used Defined here the Struct is user defined ) in the Qt Designer by any means ?.
As i Know there are two ways Either Q_PROPERTY Which works for the Qt defined type and the other is QDesignerPropertySheetExtension
Currently i am using the QDesinerPropertySheetExtension but the Property class is not coming
So plz help me
Re: Custom Property On Custom Widget
How did you use QDesinerPropertySheetExtension?
Re: Custom Property On Custom Widget
I have used the qDesignerPropertySheet Extension as it was mentioned in the doc .But i dont know how to display the custom Property because anyway i have not found any method for showing the custom Property only get set or Property group methods are available
Re: Custom Property On Custom Widget
I hope you trying to create a custom widget plugin for Qt designer, is it so?
Re: Custom Property On Custom Widget
ya and i want to give the custom(compound ) property to my custom widget . I have read somewhere that this could be possible only from QdesignerPropertySheet extension but i am not able to do this .
Re: Custom Property On Custom Widget
The QDesignerPropertySheetExtension class allows you to manipulate a widget's properties which is displayed in Qt Designer's property editor. You should be proving the properties information in your QDesignerCustomWidgetInterface
Re: Custom Property On Custom Widget
Hi
Thanks For reply. I can manipulate widget property through QDesignerPropertySheetExtension But where i have to provide my property in QDesignerCustomWidgetInterface . Can u plz elaborate what u r saying
Re: Custom Property On Custom Widget
Did you read this example ?
Re: Custom Property On Custom Widget
Hi
I have just read the example .I think The only place where i can provide the compound Property is domxml function .But my Compound Property is not coming on the widget property editor so what i am missing .
I am giving u some design what i am doing
I have created a CustomProp Class Its Plugin CustomPropPlugin
Exteansion Class Subclassed from QDesignerPropertySheetExtension and the factory class derived from QExtensionFactory Ok
Now In the initialize function of plugin i am getting the extension class of Qt designer and throught that i register the manager class
I have also implemented just the method of QDesginerPropertyExtension in my Extension Class
So am i missing something or doing something wrong
Re: Custom Property On Custom Widget
How does your domXml() look?
Re: Custom Property On Custom Widget
return "<widget class=\"CustomWidgetPropertyShow\" name=\"customWidgetPropertyShow\">\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";
Also if add something it will come as dynamic property .I have just checked with adding something but it gives the flavour of dynamic Property which i don't want .I wnat the custom struct to appear as static Property
Re: Custom Property On Custom Widget
May be I asked a wrong question, we should be looking at Extension class, did you properly implement these
Code:
virtual QVariant property
( int index
) const = 0 virtual QString propertyGroup
( int index
) const = 0 virtual QString propertyName
( int index
) const = 0
Re: Custom Property On Custom Widget
Hi
I have not found very clear explanation of implementation of these function in the documenatation .so can provide me some stuff on this
Re: Custom Property On Custom Widget
Most of the functions should be clear enough, provided you understand how Qt Designer works. What did you implement in the virtual functions of Extension class?
All these virtual functions should be implemented properly for the widget custom properties to be displayed in Qt Designer.
for example if your widget has 2 QString properties "PRO1", "PRO2" then implementation would like this,
Code:
int count() const { return 2; }
{
if(index == 0) return pro1;
else if(index == 1) return pro2;
}
QString propertyName
(int index
) const {
if(index
== 0) return QString("PRO1");
else if(index
== 1) return QString("PRO2");
}
note you need to implement all the functions properly..
Re: Custom Property On Custom Widget
Hi
very very Thanks. I think that now i can implement the Custom (Compound Property ) On the Widget .
Re: Custom Property On Custom Widget
Hi,
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
Re: Custom Property On Custom Widget
I not very sure, but this should work, as per documentation
Quote:
Originally Posted by Qt Documnetation
"When implementing a custom widget plugin, a pointer to Qt Designer's current QDesignerFormEditorInterface object is provided by the QDesignerCustomWidgetInterface::initialize() function's parameter."
From the QDesignerFormEditorInterface object, get the previous property editor interface instance, and map the properties in your class, like map 0 to n properties from previous property editor, and n to m are your custom properties, as you know you can get and set the 0 to n properties using previous property editor interface instance
Re: Custom Property On Custom Widget
Hi
The Problem is that how can i map those property becoz In the QDesignerPropertyEditorInterface No method is there ,also if i will go for meta object and get the Property through meta object i am not sure it will work .However i am doing work on this
By the way Thanks For Reply Sir
Re: Custom Property On Custom Widget
Quote:
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:
Code:
{
public:
protected:
private:
mutable bool mCreateExtensionCalled;
};
...then add the implementation of the factory...
Code:
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;
}
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):
Code:
{
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;
};
...and add the implementation of the custom property sheet...
Code:
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);
}
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
Re: Custom Property On Custom Widget
Hello Daniel, thanks for your post. I've tried to follow your example. Unfortunately the cast
makes Qt Designer crash.