Page 1 of 2 12 LastLast
Results 1 to 20 of 30

Thread: Custom Property On Custom Widget

  1. #1
    Join Date
    Feb 2011
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Smile 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

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Custom Property On Custom Widget

    How did you use QDesinerPropertySheetExtension?

  3. #3
    Join Date
    Feb 2011
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Custom Property On Custom Widget

    I hope you trying to create a custom widget plugin for Qt designer, is it so?

  5. #5
    Join Date
    Feb 2011
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default 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 .

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default 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

  7. #7
    Join Date
    Feb 2011
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  8. #8
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Custom Property On Custom Widget

    Did you read this example ?

  9. #9
    Join Date
    Feb 2011
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  10. #10
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Custom Property On Custom Widget

    How does your domXml() look?

  11. #11
    Join Date
    Feb 2011
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  12. #12
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default 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
    Qt Code:
    1. virtual QVariant property ( int index ) const = 0
    2. virtual QString propertyGroup ( int index ) const = 0
    3. virtual QString propertyName ( int index ) const = 0
    To copy to clipboard, switch view to plain text mode 

  13. #13
    Join Date
    Feb 2011
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  14. #14
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default 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,

    Qt Code:
    1. int count() const { return 2; }
    2.  
    3. QVariant property(int index) const
    4. {
    5. if(index == 0) return pro1;
    6. else if(index == 1) return pro2;
    7. else return QVariant;
    8. }
    9.  
    10. QString propertyName(int index) const
    11. {
    12. if(index == 0) return QString("PRO1");
    13. else if(index == 1) return QString("PRO2");
    14. else return QString;
    15. }
    To copy to clipboard, switch view to plain text mode 

    note you need to implement all the functions properly..
    Last edited by Santosh Reddy; 27th June 2011 at 12:04.

  15. #15
    Join Date
    Feb 2011
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Property On Custom Widget

    Hi
    very very Thanks. I think that now i can implement the Custom (Compound Property ) On the Widget .

  16. #16
    Join Date
    Feb 2011
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  17. #17
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default 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

  18. #18
    Join Date
    Feb 2011
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  19. #19
    Join Date
    Jun 2012
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Property On Custom Widget

    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:

    Qt Code:
    1. class CCustomWidgetPropertySheetFactory : public QExtensionFactory
    2. {
    3. typedef QExtensionFactory inherited;
    4.  
    5. public:
    6. CCustomWidgetPropertySheetFactory(QExtensionManager * apParent);
    7.  
    8. protected:
    9. virtual QObject * createExtension(QObject * apObject, const QString & arIId, QObject * apParent) const;
    10.  
    11. private:
    12. QExtensionManager * mpExtensionManager;
    13. mutable bool mCreateExtensionCalled;
    14. };
    To copy to clipboard, switch view to plain text mode 

    ...then add the implementation of the factory...

    Qt Code:
    1. CCustomWidgetPropertySheetFactory::CCustomWidgetPropertySheetFactory(QExtensionManager * apParent)
    2. : inherited(apParent)
    3. , mpExtensionManager(apParent)
    4. , mCreateExtensionCalled(false)
    5. {}
    6.  
    7. QObject * CCustomWidgetPropertySheetFactory::createExtension(QObject * apObject, const QString & arIId, QObject /* QExtensionFactory */ * apParent) const
    8. {
    9. QObject * lResult(0);
    10.  
    11. if (!mCreateExtensionCalled)
    12. {
    13. // note: setting flag to avoid infinite loop caused by later usage of qt_extension<>
    14. mCreateExtensionCalled = true;
    15.  
    16. if (arIId == Q_TYPEID(QDesignerPropertySheetExtension))
    17. {
    18. CCustomWidget * lCustomWidget(qobject_cast<CCustomWidget *>(apObject));
    19. if (lCustomWidget)
    20. {
    21. QDesignerPropertySheetExtension * lDefaultPropertySheetExtensionImplementor(qt_extension<QDesignerPropertySheetExtension *>(mpExtensionManager, apObject));
    22. if (lDefaultPropertySheetExtensionImplementor)
    23. {
    24. lResult = new CCustomWidgetPropertySheetExtension(apParent, *lDefaultPropertySheetExtensionImplementor);
    25. }
    26. }
    27. }
    28.  
    29. mCreateExtensionCalled = false;
    30. }
    31.  
    32. return lResult;
    33. }
    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):

    Qt Code:
    1. class CCustomWidgetPropertySheetExtension : public QObject, public QDesignerPropertySheetExtension
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. CCustomWidgetPropertySheetExtension(QObject * apParent,
    7. QDesignerPropertySheetExtension & apDefaultPropertySheetExtension);
    8. virtual ~CCustomWidgetPropertySheetExtension();
    9.  
    10. virtual int count() const;
    11.  
    12. virtual int indexOf(const QString &name) const;
    13.  
    14. virtual QString propertyName(int index) const;
    15.  
    16. virtual QString propertyGroup(int index) const;
    17.  
    18. virtual bool isVisible(int index) const;
    19.  
    20. virtual QVariant property(int index) const;
    21.  
    22. ...
    23.  
    24. private:
    25. QDesignerPropertySheetExtension & mpDefaultPropertySheetExtension;
    26. int mPropertyCount;
    27. };
    To copy to clipboard, switch view to plain text mode 

    ...and add the implementation of the custom property sheet...

    Qt Code:
    1. CCustomWidgetPropertySheetExtension::CCustomWidgetPropertySheetExtension(QObject * apParent,
    2. QDesignerPropertySheetExtension & apDefaultPropertySheetExtension)
    3. : QObject(apParent)
    4. , mpDefaultPropertySheetExtension(apDefaultPropertySheetExtension)
    5. , mPropertyCount(mpDefaultPropertySheetExtension.count() + 1)
    6. {}
    7.  
    8. CCustomWidgetPropertySheetExtension::~CCustomWidgetPropertySheetExtension()
    9. {}
    10.  
    11. ...
    12.  
    13. int CCustomWidgetPropertySheetExtension::count() const
    14. {
    15. return mPropertyCount;
    16. }
    17.  
    18. int CCustomWidgetPropertySheetExtension::indexOf( const QString& name ) const
    19. {
    20. if (name == "MyCustomProperty")
    21. return mPropertyCount - 1;
    22. else
    23. return mpDefaultPropertySheetExtension.indexOf(name);
    24. }
    25.  
    26. QString CCustomWidgetPropertySheetExtension::propertyName( int index ) const
    27. {
    28. if (index == mPropertyCount - 1)
    29. return "MyCustomProperty";
    30. else
    31. return mpDefaultPropertySheetExtension.propertyName(index);
    32. }
    33.  
    34. QString CCustomWidgetPropertySheetExtension::propertyGroup( int index ) const
    35. {
    36. if (index == mPropertyCount - 1)
    37. return "MyCustomPropertyGroup";
    38. else
    39. return mpDefaultPropertySheetExtension.propertyGroup(index);
    40. }
    41.  
    42. bool CCustomWidgetPropertySheetExtension::isVisible( int index ) const
    43. {
    44. if (index == mPropertyCount - 1)
    45. return true;
    46. else
    47. return mpDefaultPropertySheetExtension.isVisible(index);
    48. }
    49.  
    50. QVariant CCustomWidgetPropertySheetExtension::property( int index ) const
    51. {
    52. if (index == mPropertyCount - 1)
    53. return QVariant(true);
    54. else
    55. return mpDefaultPropertySheetExtension.property(index);
    56. }
    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

  20. The following user says thank you to ViRuSTriNiTy for this useful post:

    Olumide (23rd October 2014)

  21. #20
    Join Date
    Jun 2013
    Posts
    8
    Thanks
    2

    Default Re: Custom Property On Custom Widget

    Hello Daniel, thanks for your post. I've tried to follow your example. Unfortunately the cast

    Qt Code:
    1. QDesignerPropertySheetExtension* defaultPropertySheetExtension = qt_extension<QDesignerPropertySheetExtension*>( m_extensionManager , object );
    To copy to clipboard, switch view to plain text mode 

    makes Qt Designer crash.

Similar Threads

  1. Custom property in designer
    By avgust in forum Newbie
    Replies: 1
    Last Post: 9th September 2010, 10:14
  2. File dialog for custom widget property?
    By TheJim01 in forum Newbie
    Replies: 1
    Last Post: 6th May 2010, 10:14
  3. Animatin a custom property
    By Luc4 in forum Qt Programming
    Replies: 2
    Last Post: 13th April 2010, 08:37
  4. Replies: 4
    Last Post: 5th March 2010, 14:20
  5. Replies: 5
    Last Post: 16th May 2006, 20:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.