Unsolved Printing with qt5
-
Hello,
i have a simple qml application. Now i want to print a textfield content.
Does anybody know where to find a complete sample code for doing that.I searched the web but i found nothing suitable.
-
Hi
QML cannot directly print as far as i know. You have to sent it to c++ side and do it there.
https://forum.qt.io/topic/57861/solved-how-to-take-a-print-in-qml/14 -
Hello, thank you for link. I used this example as template but i got my application not to run. I do not know how to handle this error message.
-
@cupressus Hi, for this error message, you just need to include <QQmlContext> (I don't know qml though)
-
Hi,
many thanks. Works fine now.
-
it prints but print quality is terrible. How can i solve that.
-
@cupressus
Ok that dont look right :)Try save image to a file and see how it looks to know if its something printer or
the image really is that bad.void pr::print(QVariant data)
{
QImage img = qvariant_cast<QImage>(data);
img.save(xxxx) <<<<<<<<<<<<<<<<<<<<< try save it
QPrinter printer;
QPrintDialog *dlg = new QPrintDialog(&printer,0);
if(dlg->exec() == QDialog::Accepted) {
QPainter painter(&printer);
painter.drawImage(QPoint(0,0),img);
painter.end();
}
} -
i have found the error. I used a white font color because the text is shown on a grey background. I have now changed the text color to black and now everything looks fine.