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:
for(int i = 0; i < myTreeView->propertyCount(); ++i)
properties <<
QString::fromLatin1(myTreeView
->property
(i
).
name());
QStringList properties;
for(int i = 0; i < myTreeView->propertyCount(); ++i)
properties << QString::fromLatin1(myTreeView->property(i).name());
To copy to clipboard, switch view to plain text mode
When applying the properties to another object I do verify that a property exists like this:
const QMetaObject* moOtherTreeView
= otherTreeView
->metaObject
();
...
// Make sure prop exists
if (moOtherTreeView->indexOfProperty(propName) < 0)
continue; // ignore this property
...
// Ok, apply property
otherTreeView->setProperty(propName, myTreeView->property(propName));
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));
To copy to clipboard, switch view to plain text mode
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
...
...
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
...
To copy to clipboard, switch view to plain text mode
My question now is how to find out whether a property is read only or not?
thanks for any reply!
Ernst
Bookmarks