- Qt 6.7
- Qt GUI
- C++ Classes
- QPageRanges
- Qt 6.7.1 Reference Documentation

# QPageRanges Class

The QPageRanges class represents a collection of page ranges. More...

Header: | #include <QPageRanges>
CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: | QT += gui
Since: | Qt 6.0

- List of all members, including inherited members
- QPageRanges is part of Painting Classes, Printer and Printing APIs, and Implicitly Shared Classes.

## Public Types

struct | Range

## Public Functions

| QPageRanges()
| QPageRanges(const QPageRanges &other)
| QPageRanges(QPageRanges &&other)
| ~QPageRanges()
void | addPage(int pageNumber)
void | addRange(int from, int to)
void | clear()
bool | contains(int pageNumber) const
int | firstPage() const
bool | isEmpty() const
int | lastPage() const
QList<QPageRanges::Range> | toRangeList() const
QString | toString() const
QPageRanges & | operator=(const QPageRanges &other)
QPageRanges & | operator=(QPageRanges &&other)

## Static Public Members

QPageRanges | fromString(const QString &ranges)

## Related Non-Members

QDataStream & | operator<<(QDataStream &stream, const QPageRanges &pageRanges)
QDataStream & | operator>>(QDataStream &stream, QPageRanges &pageRanges)

## Detailed Description

Use QPagedPaintDevice::pageRanges() to access the collection of page ranges associated with a paged device.

## Member Function Documentation

### QPageRanges::QPageRanges()

Constructs an empty QPageRanges object.

### `[noexcept]` QPageRanges::QPageRanges(const QPageRanges &other)

Constructs a QPageRanges object by copying other.

### `[noexcept]` QPageRanges::QPageRanges(QPageRanges &&other)

Constructs a QPageRanges object by moving from other.

### `[noexcept]` QPageRanges::~QPageRanges()

Destroys the page ranges.

### void QPageRanges::addPage(int pageNumber)

Adds the single page pageNumber to the ranges.

Note: Page numbers start with 1. Attempts to add page numbers smaller than 1 will be ignored with a warning.

### void QPageRanges::addRange(int from, int to)

Adds the range specified with from and to to the ranges.

Note: Page numbers start with 1. Attempts to add page numbers smaller than 1 will be ignored with a warning.

### void QPageRanges::clear()

Removes all page ranges.

### bool QPageRanges::contains(int pageNumber) const

Returns `true` if the ranges include the page pageNumber; otherwise returns `false`.

### int QPageRanges::firstPage() const

Returns the index of the first page covered by the page ranges, or 0 if the page ranges are empty.

### `[static]` QPageRanges QPageRanges::fromString(const QString &ranges)

Constructs and returns a QPageRanges object populated with the ranges from the string representation.

     QPrinter printer;
     QPageRanges ranges = QPageRanges::fromString("1-3,6-7");
     printer.setPageRanges(ranges);

In case of parsing error, returns an empty QPageRanges object.

See also isEmpty().

### bool QPageRanges::isEmpty() const

Returns `true` if the ranges are empty; otherwise returns `false`.

### int QPageRanges::lastPage() const

Returns the index of the last page covered by the page ranges, or 0 if the page ranges are empty.

### QList<QPageRanges::Range> QPageRanges::toRangeList() const

Returns a list with the values of the ranges.

### QString QPageRanges::toString() const

Returns the string representation of the page ranges.

### `[noexcept]` QPageRanges &QPageRanges::operator=(const QPageRanges &other)

Assigns other to this QPageRanges object.

### `[noexcept]` QPageRanges &QPageRanges::operator=(QPageRanges &&other)

Moves other into this QPageRanges object.

## Related Non-Members

### QDataStream &operator<<(QDataStream &stream, const QPageRanges &pageRanges)

Writes pageRanges to stream as a range string.

See also QPageRanges::toString.

### QDataStream &operator>>(QDataStream &stream, QPageRanges &pageRanges)

Reads a page ranges string from stream and stores it in pageRanges.

See also QPageRanges::fromString.