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

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

未完待续

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值