本页内容

QPrinterInfo Class

QPrinterInfo 类可用于访问有关现有打印机的信息。更多内容...

头文件: #include <QPrinterInfo>
CMake: find_package(Qt6 REQUIRED COMPONENTS PrintSupport)
target_link_libraries(mytarget PRIVATE Qt6::PrintSupport)
qmake: QT += printsupport

公共函数

QPrinterInfo()
QPrinterInfo(const QPrinter &printer)
QPrinterInfo(const QPrinterInfo &other)
~QPrinterInfo()
QPrinter::ColorMode defaultColorMode() const
QPrinter::DuplexMode defaultDuplexMode() const
QPageSize defaultPageSize() const
QString description() const
bool isDefault() const
bool isNull() const
bool isRemote() const
QString location() const
QString makeAndModel() const
QPageSize maximumPhysicalPageSize() const
QPageSize minimumPhysicalPageSize() const
QString printerName() const
QPrinter::PrinterState state() const
QList<QPrinter::ColorMode> supportedColorModes() const
QList<QPrinter::DuplexMode> supportedDuplexModes() const
QList<QPageSize> supportedPageSizes() const
QList<int> supportedResolutions() const
bool supportsCustomPageSizes() const
QPrinterInfo &operator=(const QPrinterInfo &other)

静态公共成员

QStringList availablePrinterNames()
QList<QPrinterInfo> availablePrinters()
QPrinterInfo defaultPrinter()
QString defaultPrinterName()
QPrinterInfo printerInfo(const QString &printerName)

详细说明

使用静态函数生成 QPrinterInfo 对象的列表。列表中的每个 QPrinterInfo 对象代表一台打印机,可查询其名称、支持的纸张尺寸以及是否为默认打印机。

成员函数文档

QPrinterInfo::QPrinterInfo()

构建一个空的 QPrinterInfo 对象。

另请参阅 isNull()。

[explicit] QPrinterInfo::QPrinterInfo(const QPrinter &printer)

根据printer 构建一个QPrinterInfo对象。

QPrinterInfo::QPrinterInfo(const QPrinterInfo &other)

创建other 的副本。

[noexcept] QPrinterInfo::~QPrinterInfo()

销毁QPrinterInfo 对象。对该对象中值的引用将失效。

[static] QStringList QPrinterInfo::availablePrinterNames()

返回该系统上所有可用打印机名称的列表。

建议使用此方法代替 `availablePrinters()`,因为在大多数系统上,它的运行速度会更快。

请注意,如果本地系统或远程打印服务器发生变更,该列表可能会过时。请仅在需要时实例化QPrinterInfo 对象,并在调用前始终检查其有效性。

[static] QList<QPrinterInfo> QPrinterInfo::availablePrinters()

返回一个包含该系统上所有可用打印机的QPrinterInfo 对象列表。

不建议使用此方法,因为创建每个打印机实例可能需要很长时间,尤其是当存在远程网络打印机时;此外,如果本地系统或远程打印服务器发生更改,已保留的实例可能会过时。请改用 `availablePrinterNames()`,并仅在需要时才实例化打印机实例。

QPrinter::ColorMode QPrinterInfo::defaultColorMode() const

返回此打印机的默认颜色模式。

QPrinter::DuplexMode QPrinterInfo::defaultDuplexMode() const

返回此打印机的默认双面打印模式。

QPageSize QPrinterInfo::defaultPageSize() const

返回该打印机的当前默认页面尺寸。

[static] QPrinterInfo QPrinterInfo::defaultPrinter()

返回系统上的默认打印机。

在使用返回值之前,应先通过isNull() 进行检查,以防系统中没有默认打印机。

在某些系统上,可能存在可用的打印机,但其中没有一台被设置为默认打印机。

另请参阅 isNull()、isDefault() 和availablePrinters()。

[static] QString QPrinterInfo::defaultPrinterName()

返回当前的默认打印机名称。

QString QPrinterInfo::description() const

返回打印机的通俗描述。

另请参阅 QPrinterInfo::printerName()。

bool QPrinterInfo::isDefault() const

返回此打印机当前是否为默认打印机。

bool QPrinterInfo::isNull() const

返回此QPrinterInfo 对象是否包含打印机定义。

例如,当系统上没有打印机时,调用defaultPrinter()可能会返回一个空的QPrinterInfo 对象。

bool QPrinterInfo::isRemote() const

返回该打印机是否为远程网络打印机。

QString QPrinterInfo::location() const

返回打印机的易于理解的位置信息。

QString QPrinterInfo::makeAndModel() const

返回打印机的易于理解的品牌和型号。

QPageSize QPrinterInfo::maximumPhysicalPageSize() const

返回该打印机支持的最大物理页面大小。

另请参阅 minimumPhysicalPageSize()。

QPageSize QPrinterInfo::minimumPhysicalPageSize() const

返回该打印机支持的最小物理页大小。

另请参阅 maximumPhysicalPageSize()。

[static] QPrinterInfo QPrinterInfo::printerInfo(const QString &printerName)

返回打印机printerName 。

在使用该打印机之前,应先通过 `isNull()` 检查其返回值,以防指定的打印机不存在。

另请参阅 isNull()。

QString QPrinterInfo::printerName() const

返回打印机的名称。

这是一个用于识别打印机的唯一标识符,可能无法被人类直接识别。

另请参阅 QPrinterInfo::description() 和QPrinter::setPrinterName()。

QPrinter::PrinterState QPrinterInfo::state() const

返回该打印机的当前状态。

根据平台、打印机驱动程序或打印机本身的不同,该状态可能并不总是准确的。

QList<QPrinter::ColorMode> QPrinterInfo::supportedColorModes() const

返回该打印机支持的颜色模式。

QList<QPrinter::DuplexMode> QPrinterInfo::supportedDuplexModes() const

返回该打印机支持的双面打印模式列表。

QList<QPageSize> QPrinterInfo::supportedPageSizes() const

返回该打印机支持的纸张尺寸列表。

QList<int> QPrinterInfo::supportedResolutions() const

返回该打印机支持的分辨率列表。

bool QPrinterInfo::supportsCustomPageSizes() const

返回此打印机是否支持自定义页面尺寸。

QPrinterInfo &QPrinterInfo::operator=(const QPrinterInfo &other)

将QPrinterInfo 对象设置为与other 相等。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.