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 7862471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:08:24+00:00 2026-06-02T23:08:24+00:00

I am creating a high-resolution (1200 dpi) PDF document using QPrinter and QPainter. I

  • 0

I am creating a high-resolution (1200 dpi) PDF document using QPrinter and QPainter. I am trying to draw text at the same resolution using QTextDocument::drawContents. The reason I want to use QTextDocument is because I need to include many tables and formatted text in my document.

My problem is that QTextDocument::drawContents always inserts the text at the screen resolution, which is 96 dpi in my case. All the solutions I have found thus far suggest scaling the text to achieve the correct size. However, this results in low quality text, which I cannot afford.

My question: Is there any way to draw the contents of a QTextDocument at a high resolution?

The code below creates a PDF file with 2 lines of text, one drawn using QPainter::drawText and one drawn using QTextDocument::drawContents. I have used an Arial 8pt font in order to emphasize the problem of the low quality resulting from the scaling.

// Read the screen resolution for scaling
QPrinter screenPrinter(QPrinter::ScreenResolution);
int screenResolution = screenPrinter.resolution();

// Setup the font
QFont font;
font.setFamily("Arial");
font.setPointSize(8);

// Define locations to insert text
QPoint textLocation1(20,10);
QPoint textLocation2(20,20);

// Define printer properties
QPrinter printer(QPrinter::HighResolution); 
printer.setOrientation(QPrinter::Portrait);
printer.setPaperSize(QPrinter::A4);
printer.setResolution(1200);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("test.pdf");    

// Write text using QPainter::drawText
QPainter painter;
painter.begin(&printer);
painter.setFont(font);
painter.drawText(textLocation1, "QPainter::drawText");

// Write text using QTextDocument::drawContents
QTextDocument doc;
doc.setPageSize(printer.pageRect().size());
QTextCursor cursor(&doc);
QTextCharFormat charFormat;
charFormat.setFont(font);
cursor.insertText("QTextDocument::drawContents", charFormat);
painter.save();
painter.translate(textLocation2);
painter.scale(printer.resolution()/screenResolution, printer.resolution()/screenResolution);
doc.drawContents(&painter);
painter.restore();
painter.end();
  • 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-06-02T23:08:30+00:00Added an answer on June 2, 2026 at 11:08 pm

    The QTextDocument use its own paint device for the layout which is by default at screen resolution.

    You can change it with:

    doc.documentLayout()->setPaintDevice(&printer);
    // just before
    doc.setPageSize(printer.pageRect().size());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Opensource, free XF.Network analogs (product for creating High Performance TCP/IP Server using C#.NET )
Creating a server-side socket will fail if I'm trying to use the same port
Creating a simple RPG game, first time using XNA. Trying to get my character
I am facing trouble enabling High Resolution mode in WM6 Professional. I am using
I'm looking at creating a high quality PDF from an XML source, as the
I'm looking for a high-level java graphic library for creating artistic text, watermarks, resize,
I am considering creating my own website using Java and am trying to decide
I'm creating a Rails app for students and high schools and I'm having some
I'm bumbling my way through creating a Silverlight 3 application. I need some high
Creating a JApplet I have 2 Text Fields, a button and a Text Area.

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.