views:

439

answers:

1

Hello,

I am using the QPropertyEditor from Qt-Apps.org.

is it possible to create a class with exposed Properties where the amount of properties is runtime-dynamic? So for example you have a class which represents a vector of floats with an arbitrary length which is not known at compile time. So you have a

vector<float> myFloats;

as a class member. How to expose this as a property with the Q_PROPERTY macro. So at the end I like to have the following view in the property editor widget:

  • MyClass
    • value of myFloats[0]
    • value of myFloats[1]
    • value of myFloats[2] ... ...

Thanks in advance!

+3  A: 

By using dynamic properties ...

In your class u can set at runtime the dynamic properties of that class

DynamicPropertiesClassForQPropertyEditor()
{
    QVector<int> properties;
    ///.... fill in thevalues
    for (int i=0 ; i!=properties.size() ; ++i )
    {
        const QString propertyName = QString( "value of properties[%1]").arg(i);
        setProperty( qPrintable(propertyName) ,properties.at(i) );
    }
}
TimW
Great! It is so easy...
yoursort
Next question ;) -->Is it possible to call a function when a dynamic property was edited in the PropertyEditor? Because my class is only a wrapper for another class so I have to make sure that the other class is updated when some property is changed in the ProperyEditor.
yoursort
a QDynamicPropertyChangeEvent is sent to the object
TimW