Slim
Slim

Reputation: 306

How to print(with the printer) a QML object?

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

Upvotes: 6

Views: 3979

Answers (1)

dtech
dtech

Reputation: 49289

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.

Upvotes: 6

Related Questions