summaryrefslogtreecommitdiffstats
path: root/doc/src/snippets/widgetprinting.cpp
diff options
context:
space:
mode:
authorMorten Engvoldsen <morten.engvoldsen@nokia.com>2010-09-24 11:28:32 (GMT)
committerMorten Engvoldsen <morten.engvoldsen@nokia.com>2010-09-24 11:28:32 (GMT)
commit5fbfd61d1b2d40bb6d07f34becb89dcc203325f5 (patch)
treec1845cc1cab9e1ea71b02fd8f1f64eb5fcd374aa /doc/src/snippets/widgetprinting.cpp
parentf22387610eeb3f0ae45debe4ff5bffa42d2135dd (diff)
parentcbe44744309bad1fb8e32a4fed931331ad27a3ac (diff)
downloadQt-5fbfd61d1b2d40bb6d07f34becb89dcc203325f5.zip
Qt-5fbfd61d1b2d40bb6d07f34becb89dcc203325f5.tar.gz
Qt-5fbfd61d1b2d40bb6d07f34becb89dcc203325f5.tar.bz2
Merge branch 'mimir' of git@scm.dev.nokia.troll.no:qt/qt-doc-team into mimir
Diffstat (limited to 'doc/src/snippets/widgetprinting.cpp')
-rw-r--r--doc/src/snippets/widgetprinting.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/doc/src/snippets/widgetprinting.cpp b/doc/src/snippets/widgetprinting.cpp
new file mode 100644
index 0000000..b3d5b7c
--- /dev/null
+++ b/doc/src/snippets/widgetprinting.cpp
@@ -0,0 +1,54 @@
+
+#include <QtGui>
+
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window() {
+ myWidget = new QPushButton("Print Me");
+ connect(myWidget, SIGNAL(clicked()), this, SLOT(print()));
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(myWidget);
+ setLayout(layout);
+ }
+
+private slots:
+ void print() {
+ QPrinter printer(QPrinter::HighResolution);
+
+ printer.setOutputFileName("test.pdf");
+
+//! [0]
+ QPainter painter;
+ painter.begin(&printer);
+ double xscale = printer.pageRect().width()/double(myWidget->width());
+ double yscale = printer.pageRect().height()/double(myWidget->height());
+ double scale = qMin(xscale, yscale);
+ painter.translate(printer.paperRect().x() + printer.pageRect().width()/2,
+ printer.paperRect().y() + printer.pageRect().height()/2);
+ painter.scale(scale, scale);
+ painter.translate(-width()/2, -height()/2);
+
+ myWidget->render(&painter);
+//! [0]
+ }
+
+private:
+ QPushButton *myWidget;
+};
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+
+ Window window;
+ window.show();
+
+ return app.exec();
+}
+
+#include "main.moc"
+