QtTreePropertyBrowser继承自QtreeWidget类
在Qt源码中可以找到qtpropertybrowser即属性表,路径为E:\qt5.7.1\5.7\Src\qttools\src\shared
将qtpropertybrowser编译后即可使用属性表
用法
将一个QWidget widget_2提升为QtTreePropertyBrowser
QtVariantPropertyManager*m_pVarManagerLuRu;//可修改
QtVariantPropertyManager*m_pVarManagerLuRu1;//不可修改
QtVariantEditorFactory*m_pVarFactoryLuRu;//数据工厂
m_pVarManagerLuRu = new QtVariantPropertyManager(ui->widget_2);
m_pVarManagerLuRu1 = new QtVariantPropertyManager(ui->widget_2);
m_pVarFactoryLuRu = new QtVariantEditorFactory(ui->widget_2);
ui->widget_2->setFactoryForManager(m_pVarManagerLuRu, m_pVarFactoryLuRu);//绑定工厂后,可以修改数据
显示属性
QtProperty *groupItem2 = m_pVarManagerLuRu->addProperty(QtVariantPropertyManager::groupTypeId(), QString::fromLocal8Bit("图像二值化"));
QtVariantProperty *temp201 = m_pVarManagerLuRu->addProperty(QtVariantPropertyManager::enumTypeId(), QStringLiteral("二值化方法:"));
QStringList erZhiTypes;
erZhiTypes << QString::fromLocal8Bit("固定阙值") << QString::fromLocal8Bit("局部自适应");
temp201->setAttribute("enumNames", erZhiTypes);
temp201->setValue((int)(shezhi[0].canshu[6][0]));
temp201->setToolTip("Yes");
groupItem2->addSubProperty(temp201);
QtVariantProperty *temp203 = m_pVarManagerLuRu->addProperty(QVariant::Int, QString::fromLocal8Bit("阙值大小:"));
temp203->setValue(shezhi[0].canshu[6][1]);
temp203->setToolTip("Yes");
groupItem2->addSubProperty(temp203);
ui->widget_2->addProperty(groupItem2);
当属性的值改变后获取相应的属性
connect(m_pVarManagerLuRu, &QtVariantPropertyManager::valueChanged, this, &QiXin_companyItemClass::slot_ChangeBoolList);//建立信号槽
//定义
QMap<QtProperty*, QString> m_property_dic;
QMap<QString, QtProperty *> idToProperty;
void slot_ChangeBoolList(QtProperty * property, const QVariant & value);
//创建属性时加入列表中
QtVariantProperty *temp201 = m_pVarManagerLuRu->addProperty(QtVariantPropertyManager::enumTypeId(),
m_property_dic[temp201] = "0";
QtVariantProperty *temp203 = m_pVarManagerLuRu->addProperty(QVariant::Int,
idToProperty["2"] = temp203;
//
void slot_ChangeBoolList(QtProperty * property, const QVariant & value)
{
QString str = m_property_dic[property];
if (str == "0")
{
if (property->valueText() == QString::fromLocal8Bit("固定阙值"))
{
idToProperty["2"]->setEnabled(true);
idToProperty["3"]->setEnabled(false);
idToProperty["4"]->setEnabled(false);
idToProperty["5"]->setEnabled(false);
}
else if (property->valueText() == QString::fromLocal8Bit("局部自适应"))
{
idToProperty["2"]->setEnabled(false);
idToProperty["3"]->setEnabled(true);
idToProperty["4"]->setEnabled(true);
idToProperty["5"]->setEnabled(true);
}
}
}
未完待续