Prison::Barcode Class

class Prison::Barcode
Header: #include <Prison/Barcode>
CMake: find_package(KF6 REQUIRED COMPONENTS Prison)
target_link_libraries(mytarget PRIVATE KF6::Prison)
Since: 6.0

Public Types

enum Dimensions { NoDimensions, OneDimension, TwoDimensions }

Public Functions

QColor backgroundColor() const
(since 5.85) QByteArray byteArrayData() const
QString data() const
Prison::Barcode::Dimensions dimensions() const
QColor foregroundColor() const
Prison::BarcodeType format() const
QSizeF minimumSize() const
(since 5.69) QSizeF preferredSize(qreal devicePixelRatio) const
void setBackgroundColor(const QColor &backgroundcolor)
(since 5.85) void setData(const QByteArray &data)
void setData(const QString &data)
void setForegroundColor(const QColor &foregroundcolor)
QImage toImage(const QSizeF &size)

Static Public Members

std::optional<Prison::Barcode> create(Prison::BarcodeType type)

Detailed Description

A barcode generator for a fixed barcode format.

Note: This replaces Prison::createBarcode and AbstractBarcode* from KF5. You can create Barcode instances directly now and specify the format in its constructor. Rather than checking for createBarcode returning a nullptr, check whether the format is not Prison::Null.

Member Type Documentation

enum Barcode::Dimensions

Dimensions of the barcode.

ConstantValueDescription
Prison::Barcode::NoDimensions0Null barcode
Prison::Barcode::OneDimension1One-dimension barcode
Prison::Barcode::TwoDimensions22D matrix code

Member Function Documentation

QColor Barcode::backgroundColor() const

Returns the background color (by default white) to be used for the barcode.

See also setBackgroundColor().

[since 5.85] QByteArray Barcode::byteArrayData() const

Binary data encoded in this barcode.

This returns an empty QByteArray if textual content is set.

This function was introduced in 5.85.

See also data().

[static] std::optional<Prison::Barcode> Barcode::create(Prison::BarcodeType type)

Create a new barcode generator.

If a format is requested that is not supported by the current build due to missing/disabled optional dependencies, Barcode::format() will return Prison::Null.

QString Barcode::data() const

Textual content encoded in this barcode.

This returns an empty QString if binary content is set.

See also setData() and byteArrayData().

Prison::Barcode::Dimensions Barcode::dimensions() const

Returns the amount of dimensions of the barcode.

QColor Barcode::foregroundColor() const

Returns the foreground color (by default black) to be used for the barcode.

See also setForegroundColor().

Prison::BarcodeType Barcode::format() const

Barcode format of this barcode generator.

QSizeF Barcode::minimumSize() const

The minimal amount of pixels needed to represent this barcode without loss of information.

That is, the size of the barcode image if each line or dot is just one pixel wide. On normal screens that is not enough for barcode scanners to reliably detect the barcode though.

See also preferredSize.

[since 5.69] QSizeF Barcode::preferredSize(qreal devicePixelRatio) const

The recommended size for this barcode when shown on a screen.

This is typically significantly larger than trueMinimumSize() so that barcode scanners tend to reliably detect the code. As this depends on the physical resolution of the output, you have to pass the device pixel ration of the output screen here.

devicePixelRatio The device pixel ratio of the screen this is shown on.

This function was introduced in 5.69.

See also trueMinimumSize.

void Barcode::setBackgroundColor(const QColor &backgroundcolor)

sets the background color

backgroundcolor the new background color

See also backgroundColor().

[since 5.85] void Barcode::setData(const QByteArray &data)

Sets binary data to be drawn as a barcode.

Prefer the QString overload if your content is purely textual, to reduce the risk of encoding issues for non-ASCII content.

Calling this function does not do any repaints of anything, they are your own responsibility.

data binary barcode content

This function was introduced in 5.85.

See also data().

void Barcode::setData(const QString &data)

Sets textual data to be drawn as a barcode.

Only use this function if your content is textual, use the QByteArray overload when your content contains non-textual binary content.

Calling this function does not do any repaints of anything, they are your own responsibility.

data textual barcode content

void Barcode::setForegroundColor(const QColor &foregroundcolor)

sets the foreground color

foregroundcolor the new foreground color

See also foregroundColor().

QImage Barcode::toImage(const QSizeF &size)

Creates a image with a barcode on

Returns QImage with a barcode on, trying to match the requested size

If one of the dimensions of size is smaller than the matching dimension in minimumSize(), a null QImage will be returned