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
使用
- 在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
- 在vs中,可以将
qttools
的shared目录下
的所有.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之外的头文件全部选中并右击,在配置属性中更改moc
的Dynamic C++ Source
为Disable
即可
参考:
https://blog.csdn.net/qq_37996632/article/details/115337891