Table tree control QtTreePropertyBrowser compiled DLL (Designer plug-in)

I. Review

An article on the super practical form tree control --QtTreePropertyBrowser talked about how to compile QtTreePropertyBrowser library, and can be simple and practical. Since I downloaded version is based on Qt4 libraries, so it is also hard to compile Bala, for a long time to change the source code was compiled through.

This article is to explain how our core library compiled into this dynamic library for other modules to dynamically call.

Here the official introduction of the module QtSolutions Qt maintenance, inside contains the QtTreePropertyBrowser this project, the key is Qt5 can directly compile.

QtSolutions inside just have QtTreePropertyBrowser this project, but also contains several useful modules Finally, will simply do the introduction.

Here we mainly to explain QtTreePropertyBrowser around the library. .

Second, the dynamic compiler libraries

Compiled DLL There are two ways, one is a command line tool vs the other is, in fact, are essentially the same, are used msvc compiler.

If you want to use another compiler, this article can be used as a reference, it may not be practical in some places.

Compile this long-term maintenance of the project, we first of all is to see documentation of the code, there are usually compilation step.

This library is no exception, see figure above red circle out of money, that is, the steps we have compiled simple.

configure.bat, if you need a dynamic library you need to add -libraryparameters

1, the command-line compiler libraries and dynamic test procedures

Command line cd to the root directory of the source code, you can perform the following steps

  1. confiture.bat -library
  2. qmake
  3. nmake

No suspense, the code should be able to properly compile, here is not to do too much explanation.

Focus look how to use tools to compile vs

2, vs tools to compile a dynamic library and test program

First of casual online search for the next turn pro sln engineering article, is the following two sentences sum up

qmake xxx.pro
qmake -tp vc -r

For our qtpropertybrowser code might like this

qmake qtpropertybrowser.pro
qmake -tp vc -r

If you do not use this method, you can use vs-addin plug directly open pro file

After the completion of the implementation of the above two sentences, you will find more than a qtpropertybrowser.sln our project file in the root directory. Under each project folder can have a simple.vcxproj project file.

The next step is to open the project file qtpropertybrowser.sln with vs, then compiled.

Command line generated QtSolutions_PropertyBrowser-head.vcxproj this project file has some minor problems, need to be modified under the project configuration, otherwise the compilation will fail.

Open the Project Properties -> C / C ++ -> Preprocessor -> Preprocessor defined term.

Modify QT_QTPROPERTYBROWSER_IMPORT macro QT_QTPROPERTYBROWSER_EXPORT

Then compile, compile the results of the dynamic library in the following figure, there is no other test procedures put out here.






3, installation documentation

INSTALL.txt according to the documentation, try the following two operations have failed

  1. Add qch file, the file is not found
  2. Use the Add command assustant -addContentFile xxx.dcfto add an error.

Later, when I saw a piece of paper to create custom documents and Assistant qt , talk about how to generate Qt help documentation, we found that there are ways to generate qch files according to qhp file, try the next, actually can .

Steps are as follows:

  1. qhelpgenerator xxx.qhp -o xxx.qch
  2. assistant -register xxx.qch

For our qtpropertybrowser code might look something like this. First, enter doc \ html directory, and then do the following

  1. qhelpgenerator qtpropertybrowser.qhp -o qtpropertybrowser.qch
  2. assistant -register qtpropertybrowser.qch

第二步也可以通过工具来添加,如上图所示。编辑菜单 -> 首选项,选中文档页签,添加自己的qch文件即可。

4、测试文档

搜索页签下输入"QtPro",搜索到结果QtProperty,如下图所示,表示我们的文档集成成功。

三、设计师插件编译

动态库都有了,设计师插件还会远吗?

自己写一个Qt插件,把需要导入到desinger中的控件都注册进来即可。

大致流程如下

1、重写QDesignerCustomWidgetInterface

WidgetInterface类继承自QDesignerCustomWidgetInterface,WidgetInterface类包含了一些默认行为,这里就不贴出来了。

class TreeBrowserInterface : public WidgetInterface
{
    Q_OBJECT
    Q_INTERFACES( QDesignerCustomWidgetInterface )

public:
    TreeBrowserInterface(QObject * parent);
    virtual QWidget * createWidget( QWidget * parent ) override;
};

2、添加到插件列表

WidgetCollectionInterface::WidgetCollectionInterface( QObject * parent /*= nullptr */ )
    : QObject(parent)
{
    d_plugins.append(new QPB::TreeBrowserInterface(this));
    d_plugins.append(new QPB::ButtonBrowserInterface(this));
    d_plugins.append(new QPB::GroupBoxBrowserInterface(this));
}

3、拷贝生成的dll

生成的设计师动态库拷贝到Qt安装目录下,具体目录为和bin同级plugins目录下的designer文件夹中

4、重启Qt Designer

重新启动设计师后,Widget Box列表中多了3个控件。






一切准备就绪,剩下的就是自己玩儿了

关于怎么写设计师插件,不是本文的重点,想学习的同学直接去百度即可

四、多说一句

qt-solutions是一个Qt官方维护的开源库,其中有8个项目,QtTreePropertyBrowser就是我们今天讲到的其中一个。

这个8个模块如下列表:

  1. qtbrowserplugin 浏览器插件
  2. qtlockedfile 锁定文件
  3. qtpropertybrowser 属性编辑器
  4. qtscriptclassic 脚本支持
  5. qtservice 提供服务属性
  6. qtsingleapplication 单例运行
  7. qtsoap SOAP协议
  8. qtwinmigrate 混合运行,qt写界面dll,集成到Win32工程中。

表格树控件QtTreePropertyBrowser的运行效果,可以到超级实用的表格树控件--QtTreePropertyBrowser这篇文章中查看。

有人说,Qt.Soluations这个库的代码时基于Qt4写的,而且最后的测试时间也是Qt4.4,最好使用Qt新版本的qtpropertybrowser代码,这里我自己也进行了测试,直接把Qt5的代码覆盖当前版本的代码,编译也是能通过的,唯一比较坑的一点就是不能作为动态库使用了。

然后我就屁颠屁颠的,把所有需要导出的类都添加了导出宏,手都给我加酸了。

随着后续对这个控件的使用,具体细节上的区别等以后再过来完善。

写到最后,使用Beyond Compare工具进行了两份代码的对比,其实本质上差别不大。 目前发现的唯一一个区别较大的就是QtTreePropertyBrowser这个类中使用的树控件问题了,Qt4时使用的是QTreeView,而到了Qt5使用的是QTreeWidget。

五、相关文章

超级实用的表格树控件--QtTreePropertyBrowser

创建文档和自定义的qt assistant

QtPropertyBrowser控件在Qt5.5上的安装配置


以上内容,基本就是本篇文章的所有内容啦!表格树控件可以使用起来了。希望可以帮到大家。


一起期待后续封装完善的控件。。。

照着文章一步一步进行,所有库应该都可以编译通过,如果实在搞不定需要工程代码的可以留邮箱




很重要--转载声明

  1. 本站文章无特别说明,皆为原创,版权所有,转载时请用链接的方式,给出原文出处。同时写上原作者:朝十晚八 or Twowords

  2. 如要转载,请原文转载,如在转载时修改本文,请事先告知,谢绝在转载时通过修改本文达到有利于转载者的目的。


Guess you like

Origin www.cnblogs.com/swarmbees/p/11129274.html