Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Printing QGraphicsScene Font Size Issue

    General and Desktop
    4
    6
    1432
    Loading More Posts
    • 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.
    • blumf
      blumf last edited by

      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.Sumi 1 Reply Last reply Reply Quote 1
      • Ni.Sumi
        Ni.Sumi @blumf last edited by

        @blumf

        Check QFontMetrics and this

        blumf 1 Reply Last reply Reply Quote 0
        • blumf
          blumf @Ni.Sumi last edited by

          @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.Sumi 1 Reply Last reply Reply Quote 0
          • Ni.Sumi
            Ni.Sumi @blumf last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • P
              patrickkidd last edited by

              I am also having this problem with Qt-5.8.

              https://vedanamedia.com/

              1 Reply Last reply Reply Quote 0
              • A
                Asperamanca last edited by

                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 Reply Quote 0
                • First post
                  Last post