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

2019-02-07 07:56发布

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

1条回答
混吃等死
2楼-- · 2019-02-07 08:06

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.

查看更多
登录 后发表回答