Results 1 to 13 of 13

Thread: User defined property & compound properties

  1. #1
    Join Date
    Nov 2010
    Posts
    57
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default User defined property & compound properties

    I just need some direction on this one.

    I want to create MyClass with some Q_PROPERTY fields then declare MyClass as a metatype so I can use it in QVarient and set it as a Q_PROPERTY of my main widget. Then MyClass properties will get added as compound properties (like geometry or font on QWidget).

    I run a Q_DECLARE_METATYPE() at the end of MyClass and qRegisterMetaType<MyClass>(); in the constructor of the widget. Declaring:
    Q_PROPERTY(MyClass myClass READ myClass WRITE setMyClass) in the header.

    It runs the setMyClass method but doesn't display anything...

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: User defined property & compound properties

    Maybe a little compiling example code?
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Nov 2010
    Posts
    57
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: User defined property & compound properties

    Here are the two classes I have. They are instantiated from a myclassplugin class as part of a Qt custom designer widget. They are very basic. "test" shows up in the properties list but "Cell" doesn't. I guess I need to do something extra to the cell to get the value data out?

    Cell.h
    Qt Code:
    1. #ifndef CELL_H
    2. #define CELL_H
    3.  
    4. #include <QObject>
    5. #include <QMetaType>
    6.  
    7. class Cell : public QObject
    8. {
    9. Q_OBJECT
    10. Q_PROPERTY( QString one READ one WRITE setOne )
    11. Q_PROPERTY( int two READ two WRITE setTwo )
    12. public:
    13. explicit Cell(QObject *parent = 0);
    14. Cell(const Cell& cell);
    15. ~Cell(){}
    16.  
    17. Cell& operator=( const Cell& cell );
    18.  
    19. QString one() const;
    20. void setOne( const QString& one );
    21. int two() const;
    22. void setTwo( const int value );
    23.  
    24. private:
    25. QString m_one;
    26. int m_two;
    27.  
    28. };
    29.  
    30. Q_DECLARE_METATYPE(Cell);
    31.  
    32. #endif // CELL_H
    To copy to clipboard, switch view to plain text mode 

    Cell.cpp
    Qt Code:
    1. #include "Cell.h"
    2.  
    3. Cell::Cell(QObject *parent) :
    4. QObject(parent)
    5. , m_one( "" )
    6. , m_two( 0 )
    7. {
    8. }
    9.  
    10. Cell::Cell(const Cell &cell)
    11. : m_one( cell.m_one)
    12. , m_two( cell.m_two )
    13. {
    14.  
    15. }
    16.  
    17.  
    18. QString Cell::one() const
    19. {
    20. return m_one;
    21. }
    22.  
    23. void Cell::setOne(const QString &one)
    24. {
    25. m_one = one;
    26. }
    27.  
    28. int Cell::two() const
    29. {
    30. return m_two;
    31. }
    32.  
    33. void Cell::setTwo(const int value)
    34. {
    35. m_two = value;
    36. }
    37.  
    38. Cell& Cell::operator =( const Cell& cell )
    39. {
    40. m_one = cell.m_one;
    41. m_two = cell.m_two;
    42. return *this;
    43. }
    To copy to clipboard, switch view to plain text mode 

    myclass.h
    Qt Code:
    1. #ifndef MYCLASS_H
    2. #define MYCLASS_H
    3.  
    4. #include <QtGui/QWidget>
    5.  
    6. #include "Cell.h"
    7.  
    8. class MyClass : public QWidget
    9. {
    10. Q_OBJECT
    11. Q_PROPERTY(Cell cell READ cell WRITE setCell)
    12. Q_PROPERTY(QString test READ test WRITE setTest)
    13.  
    14. public:
    15. MyClass(QWidget *parent = 0);
    16. ~MyClass(){}
    17.  
    18. Cell cell();
    19. void setCell(const Cell& cell);
    20.  
    21. QString test();
    22. void setTest(const QString& test);
    23.  
    24. private:
    25. Cell m_Cell;
    26. QString m_test;
    27. };
    28.  
    29. #endif
    To copy to clipboard, switch view to plain text mode 

    myclass.cpp
    Qt Code:
    1. #include "myclass.h"
    2.  
    3. MyClass::MyClass(QWidget *parent) :
    4. QWidget(parent)
    5. {
    6. qRegisterMetaType<Cell>();
    7. }
    8.  
    9. Cell
    10. MyClass::cell()
    11. {
    12. return m_Cell;
    13. }
    14.  
    15. void
    16. MyClass::setCell(const Cell &cell)
    17. {
    18. m_Cell = cell;
    19. }
    20.  
    21. MyClass::test()
    22. {
    23. return m_test;
    24. }
    25.  
    26. void
    27. MyClass::setTest(const QString &test)
    28. {
    29. m_test = test;
    30. }
    To copy to clipboard, switch view to plain text mode 

    I thought I could use the Cell's metaobject to get the property fields of Cell, but no success there yet.

    ps. I can't seem to get attachment to work right now. I will try later from another computer if it's helpful?


    Added after 15 minutes:


    I added the following to the MyClass::cell() method:
    Qt Code:
    1. const QMetaObject *metaobject = m_Cell.metaObject();
    2. int count = metaobject->propertyCount();
    3. QString tmp(QString("%1 ").arg(count));
    4. for(int i = 0; i < count; i++)
    5. {
    6. QMetaProperty metaproperty = metaobject->property(i);
    7. const char *name = metaproperty.name();
    8. QVariant value = m_Cell.property(name);
    9. this->setProperty(name, value);
    10.  
    11. tmp.append(QString("| %1 : %2 ").arg(name).arg(value.toString()));
    12. }
    13. setTest(tmp);
    To copy to clipboard, switch view to plain text mode 

    And got the result:
    3 | objectName : | one : | two : 0
    So the information is there. It just does not show up.
    Last edited by pan; 25th November 2010 at 07:54.

  4. #4
    Join Date
    Nov 2010
    Posts
    57
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: User defined property & compound properties

    Just an update for anyone interested in the future...

    It is out of the scope of the Qt designer for me to display the information that way.
    Last edited by pan; 26th November 2010 at 09:02.

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

    Default Re: User defined property & compound properties

    Hi
    have u achieved what r u talking about like properties on CustomWidget

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: User defined property & compound properties

    There is no problems with properties on custom widgets. The problem is the OP wanted to violate the rule that QObjects are not to be copied and he wanted Designer to somehow automatically detect and handle that situation for him. It is possible but it requires much more work as you need to implement the QDesignerCustomPropertySheetExtension interface through a plugin.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: User defined property & compound properties

    hi
    Can u Show some Example regarding this .I have to implement this for my custom Widget

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

    Default Re: User defined property & compound properties

    Hi I have used the QDesignerPropertySheet Extension now i am creating the This as the base class and the CustomProperty Class as memeber of this class but the Property are not Coming Where i am missing

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: User defined property & compound properties

    You are probably missing in your code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: User defined property & compound properties

    Hi
    Suppose i have created the QDesignerProperty Extension through the procedure .Now my CustomProperty class is in CustomClass and put the pointer in the Extension Class .But the Custom Property is not Coming am i missing something


    Added after 17 minutes:


    Hi ,
    need help regarding QDesinerPropertySheetExtension .I have serached the google but found nothing regarding Custom Property and QDesinerPropertySheetExtension
    Last edited by Ashutosh2k1; 23rd June 2011 at 13:58.

  11. #11
    Join Date
    Nov 2010
    Posts
    57
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: User defined property & compound properties

    What I originally wanted was a way to display properties like they do with geometry. The approach I took was obviously wrong. But support at Nokia told me it was not possible to create it the way I wanted (unless I rewrite some source I guess).

    There is a help page for QDesignerPropertySheetExtension...

    It is a bit hard to understand what you want. If you just want a property on your custom designer widget? or you want to create your own QVariant? Do you really want to mess with the properties or do you just want to add some custom ones?

    Check out Q_PROPERTY if you just want to add some extras to the existing property sheet.

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

    Default Re: User defined property & compound properties

    No Actually I want the Property Like Geometry where you can expand the fifferent memeber .For Just Showing the Property i can use Q_PROPERTY and it gives result.
    But Suppose i have defined a struct Prop whose memeber are firstand seecond so i want the the struct memeber to be appear as the property of Custom Widget and i can modify the member of struct first and second
    So my problem is this

  13. #13
    Join Date
    Nov 2010
    Posts
    57
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: User defined property & compound properties

    wysota says it is possible... I tried working with QDesignerPropertySheetExtension but didn't get it to work. If you figure out a solution it would be interesting to see what you did. Good luck.

    But after talking with the Qt people at Nokia last year I was left with this conclusion: it is possible to have compound properties but it is not possible to show them in the designer's editor in a compound format.

Similar Threads

  1. QUrl with user-defined structure
    By csoler in forum Qt Programming
    Replies: 0
    Last Post: 5th April 2010, 10:29
  2. QSqlQueryModel + user defined roles
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 7th December 2009, 07:29
  3. Resizing user defined QGraphicsItem
    By manti_madhu in forum Qt Programming
    Replies: 0
    Last Post: 9th September 2009, 09:35
  4. Using User Defined Libraries
    By csvivek in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2008, 19:47
  5. User Defined Signal?
    By rajeshs in forum Newbie
    Replies: 2
    Last Post: 18th December 2007, 11:42

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.