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. [SOLVED] Clipping problem with QPainter on QPrinter

[SOLVED] Clipping problem with QPainter on QPrinter

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.8k Views 1 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.
  • E Offline
    E Offline
    enforcer
    wrote on last edited by
    #1

    For my software I create a draw a football pitch and add players and their routes on it. saved as numbers I let it draw with QPainter. Thx to clipping everything is drawn within the specified widget. Several Formations and Plays also contains Names and Informations as plain text (for now)

    I want to export everything into a PDF document where each page contains one formation/play. The layout for each page should be like this:

    Name of Formation/Play

    Image of Formation/Play

    Information of Formation/Play

    Putting everything as QTextdocument will make the image resolution blured. The same happens with QPainter::drawImage. I only see the way to redraw everything in QPainter painting everything on QPrinter. The first tests gave me the result I wanted.

    On each page I could see some white yard lines partly covering my text. I can easily remove them with lots of queries, but the player circles still overlap with the rectangle when they are put close to its border(s). Is there a way to only clip this Image area on QPainter so that the textlines can still be displayed?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      enforcer
      wrote on last edited by
      #2

      I solved it myself, but honestly I haven't thought that it would work.

      @QPrinter printer;
      // Settings for the printer

      QPainter painter;
      painter.begin(&printer);

      // for each formation/play, do this
      printer.newPage();
      // set font with QFont for headline
      painter.drawText(0, 0, formation->getName());

      // start drawing formation in clipped area in size 640:360
      painter.setClipRect(0, 100, 640, 360);
      formation->drawFormation(&painter, 640, 360);
      painter.setClipping(false);

      // set Font for formation's/play's information
      painter.drawText(0, 0, formation->getInfo());

      // after painting everything
      painter.end()@

      Painter clips everything only if QPainter::clipping() is true. When you set clipping to false in between, than it ignores all clipping rules from that very moment.

      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