如何打印(使用打印机)QML 对象? [英] How to print(with the printer) a QML object?

查看:13
本文介绍了如何打印(使用打印机)QML 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Qt Quick 设计了一张销售收据,我想用打印机打印它.

I have designed a sales receipt with Qt Quick and I want to print it with the printer.

我该怎么做?

这是我的 ma​​in.cpp

QtQuick2ApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("qml/Caisse-MBM/main.qml"));
viewer.showFullScreen();

推荐答案

你可以使用 QQuickView::grabWindow() 得到一个 QImage 然后做任何你想做的事用它,打印它,保存它......

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.

这篇关于如何打印(使用打印机)QML 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆