3dch
11th June 2009, 17:11
I try to populate a QObject descendant with the properties of another QObject descendant to have them identical (for example set a QTreeView to have the same property values as another QTreeView). Retrieving all properties poses no problems:
QStringList properties;
for(int i = 0; i < myTreeView->propertyCount(); ++i)
properties << QString::fromLatin1(myTreeView->property(i).name());
When applying the properties to another object I do verify that a property exists like this:
const QMetaObject* moOtherTreeView = otherTreeView->metaObject();
...
QByteArray propName = properties[ix].toLatin1();
// Make sure prop exists
if (moOtherTreeView->indexOfProperty(propName) < 0)
continue; // ignore this property
...
// Ok, apply property
otherTreeView->setProperty(propName, myTreeView->property(propName));
But unfortunately some of the properties are read only, which is reported by Qt in the debug output:
...
updatesEnabled
visible
minimized
QTreeView::setProperty: Property "minimized" invalid, read-only or does not exist
maximized
QTreeView::setProperty: Property "maximized" invalid, read-only or does not exist
fullScreen
QTreeView::setProperty: Property "fullScreen" invalid, read-only or does not exist
sizeHint
...
My question now is how to find out whether a property is read only or not?
thanks for any reply!
Ernst
QStringList properties;
for(int i = 0; i < myTreeView->propertyCount(); ++i)
properties << QString::fromLatin1(myTreeView->property(i).name());
When applying the properties to another object I do verify that a property exists like this:
const QMetaObject* moOtherTreeView = otherTreeView->metaObject();
...
QByteArray propName = properties[ix].toLatin1();
// Make sure prop exists
if (moOtherTreeView->indexOfProperty(propName) < 0)
continue; // ignore this property
...
// Ok, apply property
otherTreeView->setProperty(propName, myTreeView->property(propName));
But unfortunately some of the properties are read only, which is reported by Qt in the debug output:
...
updatesEnabled
visible
minimized
QTreeView::setProperty: Property "minimized" invalid, read-only or does not exist
maximized
QTreeView::setProperty: Property "maximized" invalid, read-only or does not exist
fullScreen
QTreeView::setProperty: Property "fullScreen" invalid, read-only or does not exist
sizeHint
...
My question now is how to find out whether a property is read only or not?
thanks for any reply!
Ernst