QPrintDialog 类提供用于指定打印机配置的对话框。 更多...
头: | #include <QPrintDialog> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS PrintSupport)
target_link_libraries(mytarget PRIVATE Qt6::PrintSupport) |
qmake: | QT += printsupport |
继承: | QAbstractPrintDialog |
QPrintDialog (QPrinter * printer , QWidget * parent = nullptr) | |
QPrintDialog (QWidget * parent = nullptr) | |
virtual | ~QPrintDialog () |
void | open (QObject * receiver , const char * member ) |
QAbstractPrintDialog::PrintDialogOptions | options () const |
QPrinter * | printer () |
void | setOption (QAbstractPrintDialog::PrintDialogOption option , bool on = true) |
void | setOptions (QAbstractPrintDialog::PrintDialogOptions options ) |
bool | testOption (QAbstractPrintDialog::PrintDialogOption option ) const |
virtual void | done (int result ) override |
virtual int | exec () override |
virtual void | setVisible (bool visible ) override |
void | accepted (QPrinter * printer ) |
The dialog allows users to change document-related settings, such as the paper size and orientation, type of print (color or grayscale), range of pages, and number of copies to print.
Controls are also provided to enable users to choose from the printers available, including any configured network printers.
Typically, QPrintDialog objects are constructed with a QPrinter object, and executed using the exec () 函数。
QPrintDialog printDialog(printer, parent); if (printDialog.exec() == QDialog::Accepted) { // print ... }
If the dialog is accepted by the user, the QPrinter object is correctly configured for printing.
The printer dialog (shown above in Plastique style) enables access to common printing properties. On X11 platforms that use the CUPS printing system, the settings for each available printer can be modified via the dialog's 特性 push button.
On Windows and macOS, the native print dialog is used, which means that some QWidget and QDialog properties set on the dialog won't be respected. The native print dialog on macOS does not support setting printer options, i.e. setOptions () 和 setOption () have no effect.
In Qt 4.4, it was possible to use the static functions to show a sheet on macOS. This is no longer supported in Qt 4.5. If you want this functionality, use QPrintDialog::open ().
另请参阅 QPageSetupDialog and QPrinter .
This property holds the various options that affect the look and feel of the dialog
默认情况下,所有选项是被禁用的。
Options should be set before showing the dialog. Setting them while the dialog is visible is not guaranteed to have an immediate effect on the dialog (depending on the option and on the platform).
访问函数:
QAbstractPrintDialog::PrintDialogOptions | options () const |
void | setOptions (QAbstractPrintDialog::PrintDialogOptions options ) |
另请参阅 setOption () 和 testOption ().
[explicit]
QPrintDialog::
QPrintDialog
(
QPrinter
*
printer
,
QWidget
*
parent
= nullptr)
Constructs a new modal printer dialog for the given printer 采用给定 parent .
[explicit]
QPrintDialog::
QPrintDialog
(
QWidget
*
parent
= nullptr)
Constructs a print dialog with the given parent .
[virtual noexcept]
QPrintDialog::
~QPrintDialog
()
Destroys the print dialog.
[signal]
void
QPrintDialog::
accepted
(
QPrinter
*
printer
)
This signal is emitted when the user accepts the values set in the print dialog. The printer parameter includes the printer that the settings were applied to.
[override virtual]
void
QPrintDialog::
done
(
int
result
)
重实现: QDialog::done (int r).
关闭对话框并将其结果代码设为 result 。若此对话框的展示是采用 exec (),done() 导致本地事件循环的完成,且 exec () 返回 result .
注意: This function does not apply to the Native Print Dialog on the Mac macOS and Windows platforms, because the dialog is required to be modal and only the user can close it.
另请参阅 QDialog::done ().
[override virtual]
int
QPrintDialog::
exec
()
重实现: QDialog::exec ().
这是重载函数。
打开对话框并连接其 accepted () 信号到槽,指定通过 receiver and member .
将从槽断开信号连接,当关闭对话框时。
Returns the printer that this printer dialog operates on. This can be useful when using the QPrintDialog::open () 方法。
设置给定 option 为被启用若 on 为 true;否则,清零给定 option .
另请参阅 options and testOption ().
[override virtual]
void
QPrintDialog::
setVisible
(
bool
visible
)
重实现: QDialog::setVisible (bool visible).
返回
true
若给定
option
被启用;否则,返回 false。