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. Issue with clipping of QLegend when writing QChartView to PDF

Issue with clipping of QLegend when writing QChartView to PDF

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 49 Views
  • 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.
  • AndyBriceA Offline
    AndyBriceA Offline
    AndyBrice
    wrote last edited by
    #1

    I am writing a ChartWidget (a QWidget which contains 1 or more QChartViews) to a PDF file. This is the code to render the ChartWidget to a PDF file:

           QPdfWriter writer( filePath );
            writer.setPageSize( toQPageSize( getPdfPageSize() ) );
            writer.setPageOrientation( getPdfOrientation()  );
            writer.setResolution( getPdfResolution() );
    
            // create a new ChartWidget, so don't have to re-parent or resize current one
            QRectF pageRect = writer.pageLayout().paintRectPixels( writer.resolution() );
            QSize sz( qCeil( pageRect.width() ), qCeil( pageRect.height() ) );
            ChartWidget* chartWidget = new ChartWidget( this );
            chartWidget->setAttribute( Qt::WA_DontShowOnScreen, true );
            chartWidget->resize( sz );
            chartWidget->populate(); // QCharts and QChartViews created
    
            // render the widget to PDF
            QPainter painter( &writer );
            chartWidget->render( &painter );
    
            // cleanup
            delete chartWidget;
    

    Note that the ChartWidget is being created with the correct size for the PDF (not resized).

    This works fine on Windows.

    8b92cf90-910f-4455-8c8a-b90b8fb0ba3c-image.png

    But on Mac the QLegend is always clipped.

    a8686e4a-d7ad-44af-8a84-b77a3223dc50-image.png

    Any idea why? Is it something to do with the difference between logical and physical resolutions on Mac?

    I asked Microsoft Copilot, but it gave me some (very confident) wrong answers.

    I am on Qt 5.15.18.

    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