Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Failing to set margins when printing to pdf
Forum Updated to NodeBB v4.3 + New Features

Failing to set margins when printing to pdf

Scheduled Pinned Locked Moved QtWebEngine
2 Posts 2 Posters 1.7k 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.
  • D Offline
    D Offline
    devarde
    wrote on last edited by
    #1

    I am using Qt 5.7 + Ubuntu 16.06 64 bits. After I load a page using QWebEnginePage I try to invoke the printToPdf method of QebEnginePage (link text). One of the arguments is a PageLayout and one of the arguments to create a PageLayout is the margin:

    QPageLayout( QPageSize( QPageSize::A4 ), QPageLayout::Portrait, QMarginsF())
    

    In my case I am using

    QPageLayout( QPageSize( QPageSize::A4 ), QPageLayout::Portrait, QMarginsF(0,0,0,0))
    

    But any value that I am passing to the pageloyut is ignored in the generated PDF.
    The single way to workaround I found is to set up the following in CSS

    @page{
       margin: 0;
    }
    

    Is there any way to specify a margin via C++ code?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bui Trung
      wrote on last edited by
      #2

      Did you try this function of QPrinter ?
      http://doc.qt.io/qt-5/qprinter.html#setPageMargins

      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