Pages
API Documentation
On this page

Prison::Barcode Class

This class was introduced in Qt 6.0. More...

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

List of all members, including inherited members

Public Types

Public Functions

Static Public Members

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.

Constant Value Description
Prison::Barcode::NoDimensions 0 Null barcode
Prison::Barcode::OneDimension 1 One-dimension barcode
Prison::Barcode::TwoDimensions 2 2D 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()

QByteArray Barcode::byteArrayData() const

Binary data encoded in this barcode.

This returns an empty QByteArray if textual content is set.

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(), 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

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.

See also trueMinimumSize

void Barcode::setBackgroundColor(const QColor &backgroundcolor)

sets the background color

backgroundcolor the new background color

See also backgroundColor()

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

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

We use cookies to personalize content and to analyze our traffic. Please decide if you are willing to accept cookies from our website.