zoukankan      html  css  js  c++  java
  • ff

    #include "printer.h"
    #include <QPrinter>
    #include <QPrintPreviewDialog>
    #include <QPageSetupDialog>
    #include <QTextDocument>
    #include <QTextEdit>

    printer::printer(QWidget *parent, Qt::WFlags flags)
    : QDialog(parent, flags)
    , m_printer(NULL)
    {
    ui.setupUi(this);

    m_printer = new QPrinter();
    m_printer->setFullPage(true);
    m_printer->setOrientation(QPrinter::Portrait);
    m_printer->setOutputFormat(QPrinter::NativeFormat);
    m_printer->setPageSize(QPrinter::Custom);
    m_printer->setPaperSize(QSizeF(280, 125), QPrinter::Millimeter);

    connect(ui.m_pbPrinter, SIGNAL(clicked()), this, SLOT(print()));

    m_textEdit = new QTextEdit(this);
    m_textEdit->setGeometry(0,0, 300, 400);
    }

    printer::~printer()
    {
    delete m_printer;
    delete m_textEdit;
    }

    void printer::print()
    {
    // QPageSetupDialog setupDialog(m_printer, this);
    // setupDialog.exec();

    QPrintPreviewDialog preview(m_printer, this);
    connect(&preview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(printPreview(QPrinter*)));
    preview.exec();
    }

    void printer::printPreview(QPrinter *printer)
    {
    // QTextDocument doc;
    // QFont font;
    // font.setPointSize(10);
    //
    // doc.setDefaultFont(font);
    // doc.setPlainText(text);
    //doc.print(printer);
    m_textEdit->print(printer);

    }

  • 相关阅读:
    pat 1029. Median (25)
    pat 1040. Longest Symmetric String (25)
    pat 1037. Magic Coupon (25)
    pat 1058. A+B in Hogwarts (20)
    pat 1083. List Grades (25)
    pat 1054. The Dominant Color (20)
    pat 1042. Shuffling Machine (20)
    pat 1061. Dating (20)
    *分支-11. 计算工资
    分支-10. 计算个人所得税
  • 原文地址:https://www.cnblogs.com/yzy6806555/p/4100050.html
Copyright © 2011-2022 走看看