Results 1 to 2 of 2

Thread: [SOLVED] Custom properties not visible using Q_PROPERTY

  1. #1
    Join Date
    May 2017
    Posts
    10
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Windows

    Default [SOLVED] Custom properties not visible using Q_PROPERTY

    I have a GUI displaying a tree architecture as shown here Untitled.jpg. Each of those nodes are separate classes that are derived from the node above them. All of them inherit QObject for their implementation.
    Now I need to add a few properties to be displayed when the user selects "Properties" under the Right-Click menu of "Implicit". Selecting this opens a window like so Untitled2.jpg. I added these properties in the header file of Implicit like so :

    Qt Code:
    1. #ifndef FCIMPLICIT_H
    2. #define FCIMPLICIT_H
    3. #include <QObject>
    4. #include "Interface.h"
    5. #include "ResourceItem.h"
    6. #include "MonWindow.h"
    7. #include "FCTab.h"
    8. #include "ResourceItem.h"
    9. #include "FCAbstract.h"
    10. #include "FCInterface.h"
    11. #include "FCConnections.h"
    12. class CFCImplicit: public CResourceItem
    13. {
    14.  
    15. Q_OBJECT
    16. Q_PROPERTY(int FCPortID READ getPortID )
    17. Q_PROPERTY(QString Type READ getType )
    18. Q_PROPERTY(QString Status READ getStat )
    19. Q_PROPERTY(int WWNodeNumber READ getNodeNo )
    20. Q_PROPERTY(int WWPortNumber READ getPortNo )
    21. Q_PROPERTY(bool AutoActive READ getAuto )
    22. public:
    23. CFCImplicit(QObject*);
    24. ~CFCImplicit();
    25.  
    26. QString getType();
    27. QString getStat();
    28. int getPortID();
    29. int getPortNo();
    30. int getNodeNo();
    31. bool getAuto();
    32.  
    33.  
    34. };
    To copy to clipboard, switch view to plain text mode 

    FCinterface.h is the header of the "FCASM" node.

    The issue is that only the first property is displayed, as seen in the second picture. Is there a reason why this is happening? Am I supposed to add something to the constructor or a new function?

    The constructor for the Implicit class is
    Qt Code:
    1. CFCImplicit::CFCImplicit(QObject* parent) : CResourceItem(parent)
    2. {
    3.  
    4. fnSetProperty("objectName", QString("Implicit"));
    5. ((CResourceItem*)parent)->fnAddResources(this);
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 

    EDIT

    This is what the whole thing looks like Untitled3.jpg
    Last edited by cryomicl; 18th May 2017 at 10:31.

  2. #2
    Join Date
    May 2017
    Posts
    10
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Windows

    Default Re: Using Q_Property to display properties

    SOLUTION:

    I just had to add the WRITE accessor function. I found this solution http://www.qtcentre.org/threads/3615...in-Qt-Designer

    I have no idea why WRITE is required when the Qt docs themselves state that only READ is necessary and the rest are optional, but there you go. It works now! Cheers!

Similar Threads

  1. Display QStandardItem Properties in a QTableView row
    By Phlucious in forum Qt Programming
    Replies: 3
    Last Post: 18th December 2012, 01:19
  2. Replies: 0
    Last Post: 18th April 2011, 02:21
  3. Can I display/print properties of QWidget?
    By dpatel in forum Qt Programming
    Replies: 5
    Last Post: 25th November 2010, 13:57
  4. Display File Properties [Solved]
    By DrDonut in forum Qt Programming
    Replies: 3
    Last Post: 5th May 2009, 12:45
  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.