Zint Barcode Generator and Zint Barcode Studio User Manual

B Qt Backend QZint

Annex B. Qt Backend QZint

Used internally by Zint Barcode Studio to display the preview, the Qt Backend QZint renders a barcode by drawing the vector representation (see 5.5 Buffering Symbols in Memory (vector)) provided by the Zint library libzint.

The main class is Zint::QZint, which has getter/setter properties that correspond to the zint_symbol structure (see 5.7 Setting Options), and a main method render() which takes a Qt QPainter to paint with, and a QRectF rectangular area specifying where to paint into:

/* Encode and display barcode in `paintRect` using `painter`.
   Note: legacy argument `mode` is not used */
void render(QPainter& painter, const QRectF& paintRect,
            AspectRatioMode mode = IgnoreAspectRatio);

render() will emit one of two Qt signals - encoded on successful encoding and drawing, or errored on failure. The client can connect and act appropriately, for instance:

connect(qzint, SIGNAL(encoded()), SLOT(on_encoded()));
connect(qzint, SIGNAL(errored()), SLOT(on_errored()));

where qzint is an instance of Zint::QZint and on_encoded() and on_error() are Qt slot methods provided by the caller. On error, the error value and message can be retrieved by the methods getError() and lastError() respectively.

The other main method is save_to_file():

/* Encode and print barcode to file `filename`.
   Only sets `getError()` on error, not on warning */
bool save_to_file(const QString& filename); // `ZBarcode_Print()`

which takes a filename to output to. It too will emit an errored signal on failure, returning false (but nothing on success, which just returns true). Note that rotation is achieved through the setter method setRotateAngleValue() (as opposed to the rotate_angle argument used by ZBarcode_Print()).

Various other methods are available, for instance methods for testing symbology capabilities, and utility methods such as defaultXdim() and getAsCLI().

For full details, see "backend_qt/qzint.h".