I have designed a sales receipt with Qt Quick and I want to print it with the printer.
How can I do this?
Here is my main.cpp
QtQuick2ApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("qml/Caisse-MBM/main.qml"));
viewer.showFullScreen();
QML doesnot have any such mechanism of printing. You will need to make use of Qt's C++ API's for actual printing. First you can grab image of any Item using grabToImage the result will be delegated to a callback. Inside it you can get the grabbed image data which is actually a QImage .
Qt provides extensive cross-platform support for printing. Using the printing systems on each platform, Qt applications can print to attached printers and across networks to remote printers. Qt's printing system also supports PDF file generation, providing the foundation for basic report generation facilities.
You can use QQuickView::grabWindow()
to get a QImage
and then do whatever you want with it, print it, save it...
QImage image = view->grabWindow();
Afterwards you can follow this post to get the image to print.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With