Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Printing QGraphicsScene Font Size Issue
Forum Updated to NodeBB v4.3 + New Features

Printing QGraphicsScene Font Size Issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 2.0k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • blumfB Offline
    blumfB Offline
    blumf
    wrote on last edited by
    #1

    Very simple example. I've made a QGraphicsObject based class with the painter event as:

    void MyGfxObj::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    {
    	QRectF rect(10.0,10.0, 100.0,100.0);
    
    	QFont font("Arial");
    	font.setPointSizeF(12.0);
    	painter->setFont(font);
    
    	painter->drawText(rect, "Test");
    	painter->drawRect(rect);
    }
    

    And that renders fine on-screen. But when I try to render the graphics scene to a printer

    void MainWindow::print()
    {
    	QPrinter printer(QPrinter::HighResolution);
    	printer.setPageSize(QPrinter::A4);
    
    	QPrintDialog *dialog = new QPrintDialog(&printer, this);
    	if (dialog->exec() == QDialog::Accepted) {
    		QPainter painter(&printer);
    		scene.render(&painter);
    	}
    }
    

    The text appears completely the wrong size (much bigger).
    Why isn't the text being scaled to the device correctly?

    Ni.SumiN 1 Reply Last reply
    1
    • blumfB blumf

      Very simple example. I've made a QGraphicsObject based class with the painter event as:

      void MyGfxObj::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
      {
      	QRectF rect(10.0,10.0, 100.0,100.0);
      
      	QFont font("Arial");
      	font.setPointSizeF(12.0);
      	painter->setFont(font);
      
      	painter->drawText(rect, "Test");
      	painter->drawRect(rect);
      }
      

      And that renders fine on-screen. But when I try to render the graphics scene to a printer

      void MainWindow::print()
      {
      	QPrinter printer(QPrinter::HighResolution);
      	printer.setPageSize(QPrinter::A4);
      
      	QPrintDialog *dialog = new QPrintDialog(&printer, this);
      	if (dialog->exec() == QDialog::Accepted) {
      		QPainter painter(&printer);
      		scene.render(&painter);
      	}
      }
      

      The text appears completely the wrong size (much bigger).
      Why isn't the text being scaled to the device correctly?

      Ni.SumiN Offline
      Ni.SumiN Offline
      Ni.Sumi
      wrote on last edited by
      #2

      @blumf

      Check QFontMetrics and this

      blumfB 1 Reply Last reply
      0
      • Ni.SumiN Ni.Sumi

        @blumf

        Check QFontMetrics and this

        blumfB Offline
        blumfB Offline
        blumf
        wrote on last edited by
        #3

        @Ni.Sumi I know how to get the metrics of the font, what I don't understand is why a 12pt font is rendered at over 72pt when printing

        To be explicit; why does .setPointSizeF(12.0) not result in a 12pt font when printing?

        Ni.SumiN 1 Reply Last reply
        0
        • blumfB blumf

          @Ni.Sumi I know how to get the metrics of the font, what I don't understand is why a 12pt font is rendered at over 72pt when printing

          To be explicit; why does .setPointSizeF(12.0) not result in a 12pt font when printing?

          Ni.SumiN Offline
          Ni.SumiN Offline
          Ni.Sumi
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • P Offline
            P Offline
            patrickkidd
            wrote on last edited by
            #5

            I am also having this problem with Qt-5.8.

            https://alaskafamilysystems.com/

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Asperamanca
              wrote on last edited by
              #6

              Easiest explanation would be a wrong dpi resolution. Dump printer.resolution() and check whether it makes sense for the printer you have. You can also try to change the DPI setting using printer.setResolution(dpi)

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved