6

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();
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Slim
  • 306
  • 3
  • 11

1 Answers1

6

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.

Community
  • 1
  • 1
dtech
  • 47,916
  • 17
  • 112
  • 190
  • I don't have the **view** object in my cpp. And how to call a method which makes all of that from my QML files ? Note : I have included my **main.cpp** in the question. – Slim May 28 '13 at 17:21
  • @slimit-tn - in your case it is `viewer` – dtech May 28 '13 at 17:26
  • No, the problem is that i want to execute **grabWindow()** on a child of a child of a child of the view object. For that i have passed the QImage as a Context Parameter. – Slim May 28 '13 at 22:56
  • `grabWindow()` is only available for the quick view, if you want the graphical representation of an object you are in for a treat - I've been trying to get access to the raw framebuffer data but to no avail. If I find a way to do it I will let you know. – dtech May 29 '13 at 08:40