引用Qt5 QtTreePropertyBrowser,属性输入框

QtPropertyBrowser的源码位置目录如下,在Src的qttools的shared目录下
在这里插入图片描述

如果没有安装源码,也可以在github上下载,地址如下:

qt4版本:https://github.com/qtproject/qt-solutions/tree/master/qtpropertybrowser
qt5版本:https://github.com/qt/qttools/tree/dev/src/shared/qtpropertybrowser

使用

  1. 在QtCreator中,新建个Qt项目并在.pro文件中加入这句即可引用QtPropertyBrowser

include($$[QT_INSTALL_PREFIX]/…/Src/qttools/src/shared/qtpropertybrowser/qtpropertybrowser.pri)
// 把其当做一个普通QWidget插入布局即可显示

auto property = new QtTreePropertyBrowser(this);
main_layout->addWidget(property);

效果如下图所示,但是因为没有设置内容,所以控件里面是空的。
![在这里插入图片描述](https://img-blog.csdnimg.cn/295d84ad5ef44ba7bb7a8ea0b051302c.png

  1. 在vs中,可以将qttoolsshared目录下的所有.h/.cpp文件添加到现有项中
    在这里插入图片描述但是此时生成解决方案的话,会出现“使用了未定义类型“QtVariantPropertyManagerPrivate...”的错误

这个问题的原因和解决方法如下面文字所述:

The problem is your project is set up to compile the generated moc_XXX.cpp files for the qtpropertybrowser headers .
In this case they are included at the end of qtXXX.cpp files and are not meant to be compiled separately, as they make use of the private implementation in the ccp.

To fix this, in VS, select all the qtXXX.h files from qtpropertybrowser (except for the qtXXX_p.h). Right click and select Properties.
In the property page go to Configuration Properties -> Qt Meta-Object-Compiler -> moc and set Dynamic C++ Source to Disable. This will exclude generated moc_ files from direct compilation. They will be compiled as an include in the cpp files from qtpropertybrowser, the way they were meant to be.

解决方法:将除了qtpropertybrowserutils_p.h之外的头文件全部选中并右击,在配置属性中更改mocDynamic C++ SourceDisable即可
在这里插入图片描述

参考:
https://blog.csdn.net/qq_37996632/article/details/115337891

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值