[Qt-interest] QPrinter & QPainter
Rick Vernam
rickv at hobi.com
Fri Mar 27 17:07:33 CET 2009
So I'm trying to print via qpainter.
If I go the route in the documentation it works just fine:
QPrinter printer;
printer.setPrinterName("xyz");
printer.setPaperSize(...);
QPainter painter(&printer);
painter.setRenderHint(QPainter::Antialiasing);
lblPreview->scene()->render(&painter);
However, I'd like to define a QPrinter & QPainter at the class level, then when
I need to print, I want to just call QPainter::begin, set anti-aliasing &
render.
I'm thinking I should be able to define the printer & the painter like so:
class ReceiveLoadDialog : public QDialog
{
Q_OBJECT
public:
[ ... ]
private:
[ ... ]
QPrinter printer;
QPainter painter;
[ ... ]
};
Then in the class constructor, set up the printer:
ReceiveLoadDialog::ReceiveLoadDialog(...) : QDialog(parent)
{
[ ... ]
printer.setPrinterName("HPLJ4K");
printer.setPaperSize(QSizeF(4.5,3.5), QPrinter::Inch);
[ ... ]
}
Then, when I want to print:
(printLabel(bool) is a slot connected to a QPushButton::clicked(bool) signal)
void ReceiveLoadDialog::printLabel(bool)
{
painter.begin(&printer);
painter.setRenderHint(QPainter::Antialiasing);
lblPreview->scene()->render(&painter);
painter.end();
}
At the printer, I get nothing. Not a blinking light, nothing.
Cups says everything is just fine - if I print a test page, it comes out just
great.
So, I'm thinking it must be possible to do what I'm trying to do here - any
ideas?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090327/96a74d4d/attachment.html
More information about the Qt-interest-old
mailing list