Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7555517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:37:50+00:00 2026-05-30T11:37:50+00:00

I’m writing an application that prints addresses directly onto envelopes. I’m using QTextDocument and

  • 0

I’m writing an application that prints addresses directly onto envelopes. I’m using QTextDocument and the problem is that its method print() adds the page number, which is incorrect in envelopes.

Some code, in case you need it:

void MainWindow::print()
{
    QString addressText = textEdit->document()->toPlainText();
    envelopeDocument = new QTextDocument(this);
    printer.setResolution(QPrinter::HighResolution);
    printer.setPrinterName("OKI B6200(PCL6)");
    printer.setOrientation(QPrinter::Landscape);
    QFont font("Trebuchet MS");
    switch (envelopeComboBox->currentIndex()){
    case 0:
        font.setPointSize(12);
        envelopeDocument->setDefaultFont(font);
        envelopeDocument->setPlainText(addressText);
        printer.setPaperSize(QSizeF(114,225),QPrinter::Millimeter);
        printer.setPageMargins(120,60,20,15,QPrinter::Millimeter);
        break;
    case 1:
        font.setPointSize(14);
        envelopeDocument->setDefaultFont(font);
        envelopeDocument->setPlainText(addressText);
        printer.setPaperSize(QSizeF(184,262),QPrinter::Millimeter);
        printer.setPageMargins(140,100,20,20,QPrinter::Millimeter);
        break;
    case 2:
        font.setPointSize(16);
        envelopeDocument->setDefaultFont(font);
        envelopeDocument->setPlainText(addressText);

        printer.setPaperSize(QSizeF(227,324), QPrinter::Millimeter);
        printer.setPageMargins(170,120,30,40,QPrinter::Millimeter);
        break;
    }

    QPrintPreviewDialog preview (&printer,this);
    preview.setWindowFlags(Qt::Window);
    connect(&preview, SIGNAL(paintRequested(QPrinter *)),SLOT(printPreview(QPrinter *)));
    preview.exec();
}

void MainWindow::printPreview(QPrinter *p)
{
    envelopeDocument->print(p);
}

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:37:51+00:00Added an answer on May 30, 2026 at 11:37 am

    You can try the following code, it might help you…

    QPrinter printer(QPrinter::ScreenResolution);
    printer.setPaperSize(QPrinter::A4);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName( fileName );
    // printer.setPageMargins(0.925, 0.8, 0.5, 0.8, QPrinter::Inch);
    
    QSizeF paperSize;
    paperSize.setWidth(printer.width());
    paperSize.setHeight(printer.height());
    document->setHtml(html);
    document->setPageSize(paperSize); // the document needs a valid PageSize
    document->print(&printer);
    

    When you refer the source code of print(), then you will recognize that the QPointF pageNumberPos is only defined when there is no valid QTextDocument.pageSize().
    In printPage() the page number will be just printed, if pageNumberPos is not null.
    So just set a valid QTextDocumtent.pageSize() and you have no page numbers on your printed document.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a small application that prints some stickers to a special printer.
I am writing C# application that need to print data to POS STAR printer
am writing an application that plots point on a graph and am using the
I'm writing an application that listens for sound events (using messages passed in with
im writing an application that downloads and installs addons for programs which needs to
I am writing an application that downloads large files in the background. All clients
I'm writing an application that on some stage performs low-level disk operations in Linux
I am writing an application that needs to bring window of an external app
I'm writing an application that is basically just a preferences dialog, much like the
I am writing an application that if the user hits back, it may resend

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.