How to understand the Qt report implementation scheme

About the report

There is basically no report required for embedded applications, but the report function is often used in desktop applications. There are also many report tools available under Qt, which need to be selected according to specific needs. Some reports have a more regular format, while others It is quite special, so we should choose the appropriate solution according to the specific needs.

Common solutions for Qt reports

The common Qt report implementation schemes I know are as follows:

  • Read and write word through ActiveX, and realize the drawing of tables in word documents. Excel files can also be manipulated, but rely on Microsoft's COM components;
  • Qxlsx open source table operation code; this does not depend on Microsoft's offic and COM components;
  • There are also open source third-party report libraries: cutereport, KDReports, limereport, etc. Due to the urgency of the project, I did not study how to use these third-party libraries in detail. If you have time, you can take a look
  • Realized through html, this needs to be combined with QTextDocument, which is a rich text document class.
  • QPainter draws tables and data directly on QPrinter. This is a bit aggressive, that is, it makes its own wheels, but it also has advantages, that is, it is more controllable.

A brief introduction to the options

  • ActiveX relies on windows and cannot be cross-platform. If your software does not need to be cross-platform, it can also be used. The function is quite powerful. You can use word to make a template in advance, and then the program can fill the template with data.
  • Third-party libraries; if you have enough time, you can learn those third-party open source report libraries. These libraries are said to have good report effects and powerful functions.
  • Qxlsx; this is a relatively powerful open source table library, which can generate excel table files, and charts (histograms, curves, line charts, pie charts, etc.) can also be inserted into the file. I have only used its table function. Use Relatively simple, you can directly refer to the project file (.prj) of its source code. Applies to most situations.
  • html; I also tried this solution, but the effect is not good, mainly because I don’t know anything about html, so I can’t use it well...
  • QPainter drawing; QPainter can draw various graphics on any QPaintDevice class. Since it can draw any graphics, it can naturally draw a report, but the implementation process may be a bit troublesome. It needs to calculate the coordinates of the planning position, but it is very flexible. If it is more complicated or special, you can draw a template through this scheme.

It is the first time to use qt to print reports. I used qxlsx at the beginning, but the implementation effect is not very good, because the number of data rows and columns in the report is not fixed, and it needs to be printed on a piece of A4 paper. It is more troublesome to implement with qxlsx . Later, I changed the html, which was not ideal. Finally, I used QPainter to draw directly, and the effect was not bad.

The benefits of this article, free to receive Qt development learning materials package, technical video, including (C++ language foundation, C++ design pattern, introduction to Qt programming, QT signal and slot mechanism, QT interface development-image drawing, QT network, QT database programming, QT project actual combat, QSS, OpenCV, Quick module, interview questions, etc.) ↓↓↓↓↓↓See below↓↓Click on the bottom of the article to receive the fee↓↓

Guess you like

Origin blog.csdn.net/m0_60259116/article/details/130156474