Qt学习笔记(十)QtTreePropertyBrowser属性表用法及样式修改

匿名 (未验证) 提交于 2019-12-03 00:22:01

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);         }     } }

未完待续

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!