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. qt qprinter new page
Forum Updated to NodeBB v4.3 + New Features

qt qprinter new page

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 744 Views 2 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1

    ex) The picture when you go to the next page.
    0a2abe4a-b087-46f3-9a12-50ce65f2869e-image.png

    Ex) A picture that doesn't go to the next page
    f86741fc-bc78-4089-88cd-adba20eb2794-image.png

    void QCustomReportForm::BtnPrint()
    {
    	QPrinter printer(QPrinter::HighResolution);
    
    	QPainter* painter = new QPainter(&printer);
    	painter->begin(&printer);
    	
    	//printer.setPageSize(QPagedPaintDevice::A4);
    	//printer.setFullPage(true);
    
    	QRect rect = painter->viewport();
    	QPixmap buffer = m_pReportWidget->grab();
    	painter->drawPixmap(0, 0, buffer.scaled(rect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));	
    	painter->end();
    }
    
    void QReportForm::CreateTable()
    {	
    	//QTextDocument textdoc;
    
    	/*QString html = "<style>\
    		table{width=\"5000%\"; height=\"5000%\";}\
    		td{text-align: center;}</style>";*/
    		
    	QString Header("<table border=1 align=center width=\"100%\">\
    		<tr bgcolor=#5368D6>\
    			<td align=center>1</td>\
    			<td align=center>2</td>\
    			<td align=center>3</td>\
    			<td align=center>4</td>\
    			<td align=center>5</td>\
    			<td align=center>6</td>\
    			<td align=center>7</td>\
    			<td align=center>8</td>\
    			<td align=center>9</td>\
    			<td align=center>10</td>\
    		</tr>");
    
    	QString data;
    	for (int i = 0; i < 10; i++) 
    	{
    		QString strTemp = QString("<tr>\
    			<td align=center>{data}</td>\
    			<td align=center>{data}</td>\
    			<td align=center>{data}</td>\
    			<td align=center>{data}</td>\
    			<td align=center>{data}</td>\
    			<td align=center>{data}</td>\
    			<td align=center>{data}</td>\
    			<td align=center>{data}</td>\
    			<td align=center>{data}</td>\
    			<td align=center>{data}</td>\
    		</tr>");
    
    		strTemp.replace("{data}", QString("%1").arg(i));
    		data.append(strTemp);
    	}
    
    	QString HeaderEnd("</table>");
    
    	//textdoc.setHtml(Header);
    
    	this->ui.label_14->setTextFormat(Qt::RichText);
    	this->ui.label_14->setText(Header+data+HeaderEnd);
    }
    

    Is there a flag when the page goes over from the qprinter?
    And I want to print it on the next page, but how can I print it?

    mrjjM 1 Reply Last reply
    0
    • I IknowQT

      ex) The picture when you go to the next page.
      0a2abe4a-b087-46f3-9a12-50ce65f2869e-image.png

      Ex) A picture that doesn't go to the next page
      f86741fc-bc78-4089-88cd-adba20eb2794-image.png

      void QCustomReportForm::BtnPrint()
      {
      	QPrinter printer(QPrinter::HighResolution);
      
      	QPainter* painter = new QPainter(&printer);
      	painter->begin(&printer);
      	
      	//printer.setPageSize(QPagedPaintDevice::A4);
      	//printer.setFullPage(true);
      
      	QRect rect = painter->viewport();
      	QPixmap buffer = m_pReportWidget->grab();
      	painter->drawPixmap(0, 0, buffer.scaled(rect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));	
      	painter->end();
      }
      
      void QReportForm::CreateTable()
      {	
      	//QTextDocument textdoc;
      
      	/*QString html = "<style>\
      		table{width=\"5000%\"; height=\"5000%\";}\
      		td{text-align: center;}</style>";*/
      		
      	QString Header("<table border=1 align=center width=\"100%\">\
      		<tr bgcolor=#5368D6>\
      			<td align=center>1</td>\
      			<td align=center>2</td>\
      			<td align=center>3</td>\
      			<td align=center>4</td>\
      			<td align=center>5</td>\
      			<td align=center>6</td>\
      			<td align=center>7</td>\
      			<td align=center>8</td>\
      			<td align=center>9</td>\
      			<td align=center>10</td>\
      		</tr>");
      
      	QString data;
      	for (int i = 0; i < 10; i++) 
      	{
      		QString strTemp = QString("<tr>\
      			<td align=center>{data}</td>\
      			<td align=center>{data}</td>\
      			<td align=center>{data}</td>\
      			<td align=center>{data}</td>\
      			<td align=center>{data}</td>\
      			<td align=center>{data}</td>\
      			<td align=center>{data}</td>\
      			<td align=center>{data}</td>\
      			<td align=center>{data}</td>\
      			<td align=center>{data}</td>\
      		</tr>");
      
      		strTemp.replace("{data}", QString("%1").arg(i));
      		data.append(strTemp);
      	}
      
      	QString HeaderEnd("</table>");
      
      	//textdoc.setHtml(Header);
      
      	this->ui.label_14->setTextFormat(Qt::RichText);
      	this->ui.label_14->setText(Header+data+HeaderEnd);
      }
      

      Is there a flag when the page goes over from the qprinter?
      And I want to print it on the next page, but how can I print it?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Im not really sure what the pictures should tell me :)

      Is there a flag when the page goes over from the qprinter?

      No. not if you mean it will automatically tell you if you print more than can fit on one page.
      This you must keep track of yourself.

      And I want to print it on the next page, but how can I print it?

      call https://doc.qt.io/qt-5/qprinter.html#newPage
      to get a new page to print/draw on.

      I 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        Im not really sure what the pictures should tell me :)

        Is there a flag when the page goes over from the qprinter?

        No. not if you mean it will automatically tell you if you print more than can fit on one page.
        This you must keep track of yourself.

        And I want to print it on the next page, but how can I print it?

        call https://doc.qt.io/qt-5/qprinter.html#newPage
        to get a new page to print/draw on.

        I Offline
        I Offline
        IknowQT
        wrote on last edited by
        #3

        @mrjj

        In the first figure, when the number of tables increases, printing should continue to the next page, but I don't know how to print after the new page. I developed it by printing the screen of "Widget".

        mrjjM 1 Reply Last reply
        0
        • I IknowQT

          @mrjj

          In the first figure, when the number of tables increases, printing should continue to the next page, but I don't know how to print after the new page. I developed it by printing the screen of "Widget".

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @IknowQT
          Hi
          We paint when we print so to speak.
          You need to keep track of how much space of a page you used, and if it's full you must
          call newPage and continue printing the rest there.

          Since you are printing a screengrab of widgets, in your case, you have to draw only a portion of the
          image on first page and then the rest on the next page.

          1 Reply Last reply
          0
          • artwawA Offline
            artwawA Offline
            artwaw
            wrote on last edited by
            #5

            Hi, out of curiosity: I see you commented out using QTextDocument with HTML content - was QTextDocument not handling your data properly?
            Asking since from my experience QTextDocument handles paging much better and automatically than anything else and getting the print out is just one command.

            For more information please re-read.

            Kind Regards,
            Artur

            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