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. QWebFrame print with external style ?

QWebFrame print with external style ?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 473 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.
  • cfdevC Offline
    cfdevC Offline
    cfdev
    wrote on last edited by
    #1

    Hi,
    It's possible to print a QWebView -> QWebFrame with an external style style.css?
    my output pdf file isn't formated with my style.css file ?

    	QPrinter printer;
    	QPrintDialog *dialog = new QPrintDialog(&printer);
    	if ( dialog->exec() == QDialog::Accepted) {
    		QWebFrame *frame = m_view->page()->mainFrame();
    		frame->print(&printer);
    	}
    

    In my html code, there are two include file:

    <link rel="stylesheet" href="file:///D:/code/build-mcercle-Desktop_Qt_5_5_1_MinGW_32bit-Debug/debug/Chart.js/style.css" media="screen"/>
    <link rel="stylesheet" href="file:///D:/code/build-mcercle-Desktop_Qt_5_5_1_MinGW_32bit-Debug/debug/Chart.js/plucss.css" media="screen"/>
    
    1 Reply Last reply
    0
    • cfdevC Offline
      cfdevC Offline
      cfdev
      wrote on last edited by
      #2

      Ok to fix it I export view into QImage

      void mgraph::onPrintView(QPrinter *printer) {
      	QPainter painter(printer);
      	QWebPage *page = m_view->page();
      	QWebFrame *frame = page->mainFrame();
      
      	// set size of view
      	page->setViewportSize( frame->contentsSize() );
      	QImage imgView( page->viewportSize(), QImage::Format_ARGB32 );
      
      	// set painter for render
      	QPainter painterImage(&imgView);
      	frame->render(&painterImage);
      	painterImage.end();
      
      	//Scale image of printer content
      	QImage img = imgView.scaled( printer->pageRect().width(),  printer->pageRect().height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
      
      	// Draw rescaled image to painter of printer
      	painter.drawImage(QPoint(0,0), img);
      	painter.end();
      }
      
      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved