How can I read property values set in QtDesigner for a custom widget?



  • I am trying to create a new custom widget that can be used from QtDesigner. My new widget has its own properties declared in the class header...

    Q_PROPERTY(QString nodeId READ nodeId WRITE setNodeId)
    

    I added the property to the domXml() string...

               ...
               "  <property name=\"nodeId\">\n"
               "   <string>ns=4;s=device.sensor.value</string>\n"
               "  </property>\n"
               ...
    

    I then created an application that uses the widget. I drag the widget onto the main window. I set the property values using the property editor in QtDesigner.

    I can see that when the widget is instantiated that the property values are not set to those I configured in QtDesigner. Therefore I suppose I have to read the values from the application UI XML document and set them by myself in the constructor. Is this correct? Can anyone explain how I can read these values in the constructor?



  • I see in the Ui_MainWindow.h that my widget is instantiated and then the properties are set in the setupUi() method. I can now see my properties are being set with values configured in QtDesigner. This is good. No further help required. Thanks.


  • Lifetime Qt Champion

    Hi,

    Glad you found out and thanks for sharing.

    Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.