A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQPrinter</id>
		<title>C++/Qt/QPrinter - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQPrinter"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QPrinter&amp;action=history"/>
		<updated>2026-04-18T17:05:02Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QPrinter&amp;diff=1044&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QPrinter&amp;diff=1044&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QPrinter&amp;diff=1045&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QPrinter&amp;diff=1045&amp;oldid=prev"/>
				<updated>2010-05-25T10:24:40Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Get Page rectangle==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
Foundations of Qt Development\Chapter07\printing\painter\main.cpp&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2006-2007, Johan Thelin&lt;br /&gt;
 * &lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without modification, &lt;br /&gt;
 * are permitted provided that the following conditions are met:&lt;br /&gt;
 * &lt;br /&gt;
 *     * Redistributions of source code must retain the above copyright notice, &lt;br /&gt;
 *       this list of conditions and the following disclaimer.&lt;br /&gt;
 *     * Redistributions in binary form must reproduce the above copyright notice,  &lt;br /&gt;
 *       this list of conditions and the following disclaimer in the documentation &lt;br /&gt;
 *       and/or other materials provided with the distribution.&lt;br /&gt;
 *     * Neither the name of APress nor the names of its contributors &lt;br /&gt;
 *       may be used to endorse or promote products derived from this software &lt;br /&gt;
 *       without specific prior written permission.&lt;br /&gt;
 * &lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR&lt;br /&gt;
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QPrinter&amp;gt;&lt;br /&gt;
#include &amp;lt;QPrintDialog&amp;gt;&lt;br /&gt;
#include &amp;lt;QPainter&amp;gt;&lt;br /&gt;
int main( int argc, char **argv )&lt;br /&gt;
{&lt;br /&gt;
  QApplication app( argc, argv );&lt;br /&gt;
  &lt;br /&gt;
  QPrinter printer;&lt;br /&gt;
  QPrintDialog dlg( &amp;amp;printer );&lt;br /&gt;
  if( dlg.exec() == QDialog::Accepted )&lt;br /&gt;
  {&lt;br /&gt;
    QPainter painter( &amp;amp;printer );&lt;br /&gt;
    &lt;br /&gt;
    painter.setPen( Qt::black );&lt;br /&gt;
    &lt;br /&gt;
    for( int page=0; page&amp;lt;5; page++ )&lt;br /&gt;
    {&lt;br /&gt;
      painter.drawRect( printer.pageRect() );&lt;br /&gt;
      painter.drawLine( printer.pageRect().topLeft(), printer.pageRect().bottomRight() );&lt;br /&gt;
      painter.drawLine( printer.pageRect().topRight(), printer.pageRect().bottomLeft() );&lt;br /&gt;
      &lt;br /&gt;
      QRectF textArea(&lt;br /&gt;
          printer.pageRect().left()  +printer.resolution() * 0.5, &lt;br /&gt;
          printer.pageRect().top()   +printer.resolution() * 0.5, &lt;br /&gt;
          printer.pageRect().width() -printer.resolution() * 1.0, &lt;br /&gt;
          printer.pageRect().height()-printer.resolution() * 1.5 );&lt;br /&gt;
      &lt;br /&gt;
      painter.drawRect( textArea );&lt;br /&gt;
     &lt;br /&gt;
      painter.drawText( textArea, Qt::AlignTop | Qt::AlignLeft, QString( &amp;quot;Page %1&amp;quot; ).arg( page+1 ) );&lt;br /&gt;
        &lt;br /&gt;
      if( page != 4 )&lt;br /&gt;
        printer.newPage();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Get printer resolution==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
Foundations of Qt Development\Chapter07\printing\painter\main.cpp&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2006-2007, Johan Thelin&lt;br /&gt;
 * &lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without modification, &lt;br /&gt;
 * are permitted provided that the following conditions are met:&lt;br /&gt;
 * &lt;br /&gt;
 *     * Redistributions of source code must retain the above copyright notice, &lt;br /&gt;
 *       this list of conditions and the following disclaimer.&lt;br /&gt;
 *     * Redistributions in binary form must reproduce the above copyright notice,  &lt;br /&gt;
 *       this list of conditions and the following disclaimer in the documentation &lt;br /&gt;
 *       and/or other materials provided with the distribution.&lt;br /&gt;
 *     * Neither the name of APress nor the names of its contributors &lt;br /&gt;
 *       may be used to endorse or promote products derived from this software &lt;br /&gt;
 *       without specific prior written permission.&lt;br /&gt;
 * &lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR&lt;br /&gt;
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QPrinter&amp;gt;&lt;br /&gt;
#include &amp;lt;QPrintDialog&amp;gt;&lt;br /&gt;
#include &amp;lt;QPainter&amp;gt;&lt;br /&gt;
int main( int argc, char **argv )&lt;br /&gt;
{&lt;br /&gt;
  QApplication app( argc, argv );&lt;br /&gt;
  &lt;br /&gt;
  QPrinter printer;&lt;br /&gt;
  QPrintDialog dlg( &amp;amp;printer );&lt;br /&gt;
  if( dlg.exec() == QDialog::Accepted )&lt;br /&gt;
  {&lt;br /&gt;
    QPainter painter( &amp;amp;printer );&lt;br /&gt;
    &lt;br /&gt;
    painter.setPen( Qt::black );&lt;br /&gt;
    &lt;br /&gt;
    for( int page=0; page&amp;lt;5; page++ )&lt;br /&gt;
    {&lt;br /&gt;
      painter.drawRect( printer.pageRect() );&lt;br /&gt;
      painter.drawLine( printer.pageRect().topLeft(), printer.pageRect().bottomRight() );&lt;br /&gt;
      painter.drawLine( printer.pageRect().topRight(), printer.pageRect().bottomLeft() );&lt;br /&gt;
      &lt;br /&gt;
      QRectF textArea(&lt;br /&gt;
          printer.pageRect().left()  +printer.resolution() * 0.5, &lt;br /&gt;
          printer.pageRect().top()   +printer.resolution() * 0.5, &lt;br /&gt;
          printer.pageRect().width() -printer.resolution() * 1.0, &lt;br /&gt;
          printer.pageRect().height()-printer.resolution() * 1.5 );&lt;br /&gt;
      &lt;br /&gt;
      painter.drawRect( textArea );&lt;br /&gt;
     &lt;br /&gt;
      painter.drawText( textArea, Qt::AlignTop | Qt::AlignLeft, QString( &amp;quot;Page %1&amp;quot; ).arg( page+1 ) );&lt;br /&gt;
        &lt;br /&gt;
      if( page != 4 )&lt;br /&gt;
        printer.newPage();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Print out Painted page==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
Foundations of Qt Development\Chapter07\printing\painter\main.cpp&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2006-2007, Johan Thelin&lt;br /&gt;
 * &lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without modification, &lt;br /&gt;
 * are permitted provided that the following conditions are met:&lt;br /&gt;
 * &lt;br /&gt;
 *     * Redistributions of source code must retain the above copyright notice, &lt;br /&gt;
 *       this list of conditions and the following disclaimer.&lt;br /&gt;
 *     * Redistributions in binary form must reproduce the above copyright notice,  &lt;br /&gt;
 *       this list of conditions and the following disclaimer in the documentation &lt;br /&gt;
 *       and/or other materials provided with the distribution.&lt;br /&gt;
 *     * Neither the name of APress nor the names of its contributors &lt;br /&gt;
 *       may be used to endorse or promote products derived from this software &lt;br /&gt;
 *       without specific prior written permission.&lt;br /&gt;
 * &lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR&lt;br /&gt;
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QPrinter&amp;gt;&lt;br /&gt;
#include &amp;lt;QPrintDialog&amp;gt;&lt;br /&gt;
#include &amp;lt;QPainter&amp;gt;&lt;br /&gt;
int main( int argc, char **argv )&lt;br /&gt;
{&lt;br /&gt;
  QApplication app( argc, argv );&lt;br /&gt;
  &lt;br /&gt;
  QPrinter printer;&lt;br /&gt;
  QPrintDialog dlg( &amp;amp;printer );&lt;br /&gt;
  if( dlg.exec() == QDialog::Accepted )&lt;br /&gt;
  {&lt;br /&gt;
    QPainter painter( &amp;amp;printer );&lt;br /&gt;
    &lt;br /&gt;
    painter.setPen( Qt::black );&lt;br /&gt;
    &lt;br /&gt;
    for( int page=0; page&amp;lt;5; page++ )&lt;br /&gt;
    {&lt;br /&gt;
      painter.drawRect( printer.pageRect() );&lt;br /&gt;
      painter.drawLine( printer.pageRect().topLeft(), printer.pageRect().bottomRight() );&lt;br /&gt;
      painter.drawLine( printer.pageRect().topRight(), printer.pageRect().bottomLeft() );&lt;br /&gt;
      &lt;br /&gt;
      QRectF textArea(&lt;br /&gt;
          printer.pageRect().left()  +printer.resolution() * 0.5, &lt;br /&gt;
          printer.pageRect().top()   +printer.resolution() * 0.5, &lt;br /&gt;
          printer.pageRect().width() -printer.resolution() * 1.0, &lt;br /&gt;
          printer.pageRect().height()-printer.resolution() * 1.5 );&lt;br /&gt;
      &lt;br /&gt;
      painter.drawRect( textArea );&lt;br /&gt;
     &lt;br /&gt;
      painter.drawText( textArea, Qt::AlignTop | Qt::AlignLeft, QString( &amp;quot;Page %1&amp;quot; ).arg( page+1 ) );&lt;br /&gt;
        &lt;br /&gt;
      if( page != 4 )&lt;br /&gt;
        printer.newPage();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Print out text document==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the documentation of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef MAINWINDOW_H&lt;br /&gt;
#define MAINWINDOW_H&lt;br /&gt;
#include &amp;lt;QHash&amp;gt;&lt;br /&gt;
#include &amp;lt;QMainWindow&amp;gt;&lt;br /&gt;
#include &amp;lt;QTextDocumentFragment&amp;gt;&lt;br /&gt;
class QAction;&lt;br /&gt;
class QTextDocument;&lt;br /&gt;
class QTextEdit;&lt;br /&gt;
class MainWindow : public QMainWindow&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    MainWindow();&lt;br /&gt;
public slots:&lt;br /&gt;
    void openFile();&lt;br /&gt;
    void printFile();&lt;br /&gt;
    void printPdf();&lt;br /&gt;
private:&lt;br /&gt;
    QAction *printAction;&lt;br /&gt;
    QAction *pdfPrintAction;&lt;br /&gt;
    QString currentFile;&lt;br /&gt;
    QTextEdit *editor;&lt;br /&gt;
    QTextDocument *document;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
MainWindow::MainWindow()&lt;br /&gt;
{&lt;br /&gt;
    QMenu *fileMenu = new QMenu(tr(&amp;quot;&amp;amp;File&amp;quot;));&lt;br /&gt;
    fileMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Open...&amp;quot;), this, SLOT(openFile()),&lt;br /&gt;
                        QKeySequence(tr(&amp;quot;Ctrl+O&amp;quot;, &amp;quot;File|Open&amp;quot;)));&lt;br /&gt;
    printAction = fileMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Print...&amp;quot;), this, SLOT(printFile()));&lt;br /&gt;
    printAction-&amp;gt;setEnabled(false);&lt;br /&gt;
    pdfPrintAction = fileMenu-&amp;gt;addAction(tr(&amp;quot;Print as P&amp;amp;DF...&amp;quot;), this, SLOT(printPdf()));&lt;br /&gt;
    pdfPrintAction-&amp;gt;setEnabled(false);&lt;br /&gt;
    fileMenu-&amp;gt;addAction(tr(&amp;quot;E&amp;amp;xit&amp;quot;), this, SLOT(close()),&lt;br /&gt;
                        QKeySequence(tr(&amp;quot;Ctrl+Q&amp;quot;, &amp;quot;File|Exit&amp;quot;)));&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(fileMenu);&lt;br /&gt;
    editor = new QTextEdit(this);&lt;br /&gt;
    document = new QTextDocument(this);&lt;br /&gt;
    editor-&amp;gt;setDocument(document);&lt;br /&gt;
    connect(editor, SIGNAL(selectionChanged()), this, SLOT(updateMenus()));&lt;br /&gt;
    setCentralWidget(editor);&lt;br /&gt;
    setWindowTitle(tr(&amp;quot;Text Document Writer&amp;quot;));&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::openFile()&lt;br /&gt;
{&lt;br /&gt;
    QString fileName = QFileDialog::getOpenFileName(this,&lt;br /&gt;
        tr(&amp;quot;Open file&amp;quot;), currentFile, &amp;quot;HTML files (*.html);;Text files (*.txt)&amp;quot;);&lt;br /&gt;
    &lt;br /&gt;
    if (!fileName.isEmpty()) {&lt;br /&gt;
        QFileInfo info(fileName);&lt;br /&gt;
        if (info.completeSuffix() == &amp;quot;html&amp;quot;) {&lt;br /&gt;
            QFile file(fileName);&lt;br /&gt;
            &lt;br /&gt;
            if (file.open(QIODevice::ReadOnly)) {&lt;br /&gt;
                editor-&amp;gt;setHtml(file.readAll());&lt;br /&gt;
                file.close();&lt;br /&gt;
                currentFile = fileName;&lt;br /&gt;
            }&lt;br /&gt;
        } else if (info.completeSuffix() == &amp;quot;txt&amp;quot;) {&lt;br /&gt;
            QFile file(fileName);&lt;br /&gt;
            &lt;br /&gt;
            if (file.open(QIODevice::ReadOnly)) {&lt;br /&gt;
                editor-&amp;gt;setPlainText(file.readAll());&lt;br /&gt;
                file.close();&lt;br /&gt;
                currentFile = fileName;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        printAction-&amp;gt;setEnabled(true);&lt;br /&gt;
        pdfPrintAction-&amp;gt;setEnabled(true);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::printFile()&lt;br /&gt;
{&lt;br /&gt;
    QTextDocument *document = editor-&amp;gt;document();&lt;br /&gt;
    QPrinter printer;&lt;br /&gt;
    QPrintDialog *dlg = new QPrintDialog(&amp;amp;printer, this);&lt;br /&gt;
    if (dlg-&amp;gt;exec() != QDialog::Accepted)&lt;br /&gt;
        return;&lt;br /&gt;
    document-&amp;gt;print(&amp;amp;printer);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::printPdf()&lt;br /&gt;
{&lt;br /&gt;
    QPrinter printer(QPrinter::HighResolution);&lt;br /&gt;
    printer.setOutputFormat(QPrinter::PdfFormat);&lt;br /&gt;
    QPrintDialog *printDialog = new QPrintDialog(&amp;amp;printer, this);&lt;br /&gt;
    if (printDialog-&amp;gt;exec() == QDialog::Accepted)&lt;br /&gt;
        editor-&amp;gt;document()-&amp;gt;print(&amp;amp;printer);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    MainWindow *window = new MainWindow;&lt;br /&gt;
    window-&amp;gt;resize(640, 480);&lt;br /&gt;
    window-&amp;gt;show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Qprinter  printing==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the documentation of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
int main(int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
&lt;br /&gt;
    QPrinter printer;&lt;br /&gt;
    printer.setOutputFormat(QPrinter::PdfFormat);&lt;br /&gt;
    printer.setOutputFileName(&amp;quot;/foobar/nonwritable.pdf&amp;quot;);&lt;br /&gt;
    QPainter painter;&lt;br /&gt;
    if (! painter.begin(&amp;amp;printer)) { // failed to open file&lt;br /&gt;
        qWarning(&amp;quot;failed to open file, is it writable?&amp;quot;);&lt;br /&gt;
        return 1;&lt;br /&gt;
    }&lt;br /&gt;
    painter.drawText(10, 10, &amp;quot;Test&amp;quot;);&lt;br /&gt;
    if (! printer.newPage()) {&lt;br /&gt;
        qWarning(&amp;quot;failed in flushing page to disk, disk full?&amp;quot;);&lt;br /&gt;
        return 1;&lt;br /&gt;
    }&lt;br /&gt;
    painter.drawText(10, 10, &amp;quot;Test 2&amp;quot;);&lt;br /&gt;
    painter.end();&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QObject&amp;gt;&lt;br /&gt;
class Object : public QObject&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    Object(QObject *parent = 0);&lt;br /&gt;
public slots:&lt;br /&gt;
    void print();&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;object.h&amp;quot;&lt;br /&gt;
Object::Object(QObject *parent)&lt;br /&gt;
    : QObject(parent)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
void Object::print()&lt;br /&gt;
{&lt;br /&gt;
    int numberOfPages = 10;&lt;br /&gt;
    int lastPage = numberOfPages - 1;&lt;br /&gt;
&lt;br /&gt;
    QPrinter printer(QPrinter::HighResolution);&lt;br /&gt;
    printer.setOutputFileName(&amp;quot;print.ps&amp;quot;);&lt;br /&gt;
    QPainter painter;&lt;br /&gt;
    painter.begin(&amp;amp;printer);&lt;br /&gt;
    for (int page = 0; page &amp;lt; numberOfPages; ++page) {&lt;br /&gt;
        // Use the painter to draw on the page.&lt;br /&gt;
        if (page != lastPage)&lt;br /&gt;
            printer.newPage();&lt;br /&gt;
    }&lt;br /&gt;
    painter.end();&lt;br /&gt;
    qApp-&amp;gt;quit();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;object.h&amp;quot;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    Object object;&lt;br /&gt;
    QTimer timer;&lt;br /&gt;
    timer.setSingleShot(true);&lt;br /&gt;
    timer.connect(&amp;amp;timer, SIGNAL(timeout()), &amp;amp;object, SLOT(print()));&lt;br /&gt;
    timer.start(0);&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>