Results 1 to 5 of 5

Thread: Usage of QtDesignerPropertySheetExtension

  1. #1
    Join Date
    May 2011
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Usage of QtDesignerPropertySheetExtension

    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:

    Qt Code:
    1. void ButtonPlugin::initialize(QDesignerFormEditorInterface * core)
    2. {
    3. if (m_initialized)
    4. return;
    5.  
    6. QExtensionManager *manager = core->extensionManager();
    7. Q_ASSERT(manager != 0);
    8.  
    9. manager->registerExtensions(new ButtonPropertyFactory(manager), Q_TYPEID(QDesignerPropertySheetExtension));
    10.  
    11. m_initialized = true;
    12. }
    To copy to clipboard, switch view to plain text mode 

    In addition I created ButtonPropertySheetExtension.h:
    Qt Code:
    1. #include <QObject>
    2. #include <QMap>
    3. #include <QString>
    4. #include <QDesignerPropertySheetExtension>
    5. #include <QExtensionFactory>
    6.  
    7. #include "button.h"
    8.  
    9. /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    10. ButtonPropertyFactory
    11. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
    12. class ButtonPropertyFactory : public QExtensionFactory
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. ButtonPropertyFactory(QExtensionManager *parent = 0);
    18.  
    19. protected:
    20. QObject *createExtension(QObject *object, const QString &iid, QObject *parent) const;
    21. };
    22.  
    23. /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    24. ButtonPropertySheetExtension
    25. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
    26. class ButtonPropertySheetExtension : public QObject, QDesignerPropertySheetExtension
    27. {
    28. Q_OBJECT
    29.  
    30. public:
    31. ButtonPropertySheetExtension(Button* p, QObject *parent);
    32.  
    33.  
    34. int count (void) const;
    35. bool hasReset ( int index ) const;
    36. int indexOf ( const QString & name ) const;
    37. bool isAttribute ( int index ) const;
    38. bool isChanged ( int index ) const;
    39. bool isVisible ( int index ) const;
    40. QVariant property ( int index ) const;
    41. QString propertyGroup ( int index ) const;
    42. QString propertyName ( int index ) const;
    43. bool reset ( int index );
    44. void setAttribute ( int index, bool attribute );
    45. void setChanged ( int index, bool changed );
    46. void setProperty ( int index, const QVariant & value );
    47. void setPropertyGroup ( int index, const QString & group );
    48. void setVisible ( int index, bool visible );
    49.  
    50. protected:
    51.  
    52. Button* _powner;
    53. const QMetaObject* _p_metaobject;
    54.  
    55. QMap<int, QString> _PropertyGroups;
    56. };
    To copy to clipboard, switch view to plain text mode 

    And I created ButtonPropertySheetExtension.cpp:
    Qt Code:
    1. /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    2. ButtonPropertyFactory
    3. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
    4. ButtonPropertyFactory::ButtonPropertyFactory(QExtensionManager *parent)
    5. {
    6. }
    7.  
    8.  
    9. QObject *ButtonPropertyFactory::createExtension(QObject *object,
    10. const QString &iid,
    11. QObject *parent) const
    12. {
    13. if (iid != Q_TYPEID(QDesignerPropertySheetExtension))
    14. return 0;
    15.  
    16. if (Button* pbutton = qobject_cast<Button*>(object))
    17. return new ButtonPropertySheetExtension(pbutton, parent);
    18.  
    19. return 0;
    20. }
    21. /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    22. ButtonPropertySheetExtension
    23. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
    24.  
    25.  
    26. ButtonPropertySheetExtension::ButtonPropertySheetExtension(Button* p, QObject *parent) :
    27. QObject(parent),
    28. _powner(p),
    29. _p_metaobject(_powner->metaObject()),
    30. _PropertyGroups()
    31. {
    32. const int i_object_index = indexOf("objectName");
    33. setPropertyGroup(i_object_index, "QObject");
    34.  
    35. const int i_widget_index = indexOf("modal");
    36. setPropertyGroup(i_widget_index, "QWidget");
    37.  
    38. const int i_abstractbutton_index = indexOf("text");
    39. setPropertyGroup(i_abstractbutton_index, "QAbstractButton");
    40.  
    41. const int i_pushbutton_index = indexOf("autoDefault");
    42. setPropertyGroup(i_pushbutton_index, "QPushButton");
    43. }
    44.  
    45. int ButtonPropertySheetExtension::count () const
    46. {
    47. return _p_metaobject->propertyCount();
    48. }
    49.  
    50. bool ButtonPropertySheetExtension::hasReset ( int index ) const
    51. {
    52. return _p_metaobject->property(index).isResettable();
    53. }
    54.  
    55. int ButtonPropertySheetExtension::indexOf ( const QString & name ) const
    56. {
    57. return _p_metaobject->indexOfProperty( name.toLatin1().constData() );
    58. }
    59.  
    60. bool ButtonPropertySheetExtension::isAttribute ( int index ) const
    61. {
    62. Q_UNUSED(index)
    63. return false;
    64. }
    65.  
    66. bool ButtonPropertySheetExtension::isChanged ( int index ) const
    67. {
    68. Q_UNUSED(index)
    69. return false;
    70. }
    71.  
    72. bool ButtonPropertySheetExtension::isVisible ( int index ) const
    73. {
    74. Q_UNUSED(index)
    75. return true;
    76. }
    77.  
    78. QVariant ButtonPropertySheetExtension::property ( int index ) const
    79. {
    80. return _p_metaobject->property(index).read(_powner);
    81. }
    82.  
    83. QString ButtonPropertySheetExtension::propertyGroup ( int index ) const
    84. {
    85. QMap<int, QString>::const_iterator it = _PropertyGroups.begin();
    86. if (index > 0){
    87. while (it.key() <= index){
    88. it++;
    89. }
    90. it--;
    91. }
    92. return it.value();
    93. }
    94.  
    95. QString ButtonPropertySheetExtension::propertyName ( int index ) const
    96. {
    97. return QString(_p_metaobject->property(index).name());
    98. }
    99.  
    100. bool ButtonPropertySheetExtension::reset ( int index )
    101. {
    102. return _p_metaobject->property(index).reset(_powner);
    103. }
    104.  
    105. void ButtonPropertySheetExtension::setAttribute ( int index, bool attribute )
    106. {
    107. Q_UNUSED(index)
    108. Q_UNUSED(attribute)
    109. }
    110.  
    111. void ButtonPropertySheetExtension::setChanged ( int index, bool changed )
    112. {
    113. Q_UNUSED(index)
    114. Q_UNUSED(changed)
    115. }
    116.  
    117. void ButtonPropertySheetExtension::setProperty ( int index, const QVariant & value )
    118. {
    119. QMetaProperty metaproperty = _p_metaobject->property(index);
    120. metaproperty.write(_powner, value);
    121. }
    122.  
    123. void ButtonPropertySheetExtension::setPropertyGroup ( int index, const QString & group )
    124. {
    125. _PropertyGroups.insert(index, group);
    126. }
    127.  
    128. void ButtonPropertySheetExtension::setVisible ( int index, bool visible )
    129. {
    130. Q_UNUSED(index)
    131. Q_UNUSED(visible)
    132. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Usage of QtDesignerPropertySheetExtension

    So my question, why is the attribute "icon" of QAbstractButton not shown in QtDesigner?
    Where in the code above do you use QAbstractButton?

    Edit:

    Warning: Qt Designer uses the QDesignerPropertySheetExtension to feed its property editor. Whenever a widget is selected in its workspace, Qt Designer will query for the widget's property sheet extension. If the selected widget has an implemented property sheet extension, this extension will override the default property sheet.
    You need to add the icon property manually?

  3. #3
    Join Date
    May 2011
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Usage of QtDesignerPropertySheetExtension

    Mm. Sorry. Perhaps it was the wrong question.

    My Button class owns the Properties from QAbstractButton, even "icon".
    In the function isVisible(), I always return true. Because of this all properties should be visible. (You can Debug here, icon is visible)

    But icon is not shown.....

  4. #4
    Join Date
    May 2011
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Usage of QtDesignerPropertySheetExtension

    You need to add the icon property manually?
    Reallly? Why is the - for example - PaletteEditorButton by a Property of the type QVariant::Palette shown, but not the PixmapEditor by a Property of the type QVariant::Pixmap/Icon?

    If I have to implement the PixmapEditor/"QFileDialog to choose a pixmap for the icon" by myself, I won't see any interface for configuring the appearance; to dock - for example - a QFileDialog into the Value-Column of the PropertyEditor. I don't know how. Do you have any examples/ideas?

    .... The whole mechanism is a big mysterium, and you can't find a good documentation in web...

  5. #5
    Join Date
    May 2011
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Usage of QtDesignerPropertySheetExtension

    If I have to implement the PixmapEditor/"QFileDialog to choose a pixmap for the icon" by myself, I won't see any interface for configuring the appearance; to dock - for example - a QFileDialog into the Value-Column of the PropertyEditor.
    If you create your own CustomWidget class with a property of a new metatype, there will be no possibility to show/edit this property in the QDesignerPropertyEditor. Even special types of QVariant are not supported.
    There is no interface to update the functionality of the QDesignerPropertyEditor.

    If you are interested in a workaround of the QDesignerPropertyEditor, please vote for this topic:
    http://bugreports.qt.nokia.com/browse/QTBUG-2074

Similar Threads

  1. QEffects.cpp usage.....
    By Naveen in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2011, 11:07
  2. QML usage
    By icek in forum Qt Programming
    Replies: 0
    Last Post: 5th August 2010, 17:02
  3. Usage of QT_TR_NOOP()
    By kichi in forum Newbie
    Replies: 5
    Last Post: 4th May 2009, 19:14
  4. QSqlDatabase usage
    By goes2bob in forum Newbie
    Replies: 4
    Last Post: 10th February 2008, 15:03
  5. Qt4 XML usage
    By kandalf in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2006, 20:18

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
  •  
Qt is a trademark of The Qt Company.