QtVariantPropertyManager属性管理
2021-04-26 本文已影响0人
田陌允
使用qtpropertybrowser子库,在程序pro文件中添加:
SUBDIRS += qtpropertybrowser
qtpropertybrowser.file = $$PWD/3rdParty/qtpropertybrowser/qtpropertybrowser.pro
使用:
QtVariantPropertyManager m_manager;
QtVariantEditorFactory m_factory;
CPropertyEditorUIBase (继承自QtTreePropertyBrowser)
ui->Editor->setFactoryForManager(&m_manager, &m_factory);
connect(&m_manager, SIGNAL(valueChanged(QtProperty*, const QVariant&)),
this, SLOT(onValueChanged(QtProperty*, const QVariant&)));//属性更改响应槽函数
...
...
...
void CAttributesEditorUI::onValueChanged(QtProperty *property, const QVariant &val)
{
// QVariant &val 属性值(QVariant 容器可盛放几乎所有数据类型)
ui->Editor->updateTooltip(dynamic_cast<QtVariantProperty*>(property));
if (!m_scene || m_items.isEmpty())
return;
// no subprops
if (!ui->Editor->topLevelItem(property))
return;
auto attrId = property->propertyName().toLatin1();//属性名称
qDebug()<<"*****onValueChanged "<<attrId;
for (auto sceneItem : m_items)
{
sceneItem->setAttribute(attrId, val);//属性设置,更改对象属性响应(改变尺寸大小等)
}
// store state
m_scene->addUndoState();
}