[SOLVED] Clipping problem with QPainter on QPrinter
-
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?
-
I solved it myself, but honestly I haven't thought that it would work.
@QPrinter printer;
// Settings for the printerQPainter 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.