PDA

View Full Version : print preview



wbt_ph
26th July 2009, 08:21
I use the QPrintPreviewDialog with no problem.

1) Is it normal that after pressing the print button print dialog, the Print Preview also closes?

2) When choosing what pages to print in the print dialog, it still prints from the beginning or from page 1.

Are these bugs in the QPrintPreviewDialog?

Thank you.

Wilbert

ChrisW67
27th July 2009, 23:14
1) Is it normal that after pressing the print button print dialog, the Print Preview also closes?
AFAICT that is normal operation.

2) When choosing what pages to print in the print dialog, it still prints from the beginning or from page 1.
You need to fetch and use the fromPage(), toPage(), and numCopies() values from your QPrinter (passed into paintRequested()) and do something like:


void MyClass::printPages(QPainter *painter)
{
int firstPage = m_printer->fromPage() - 1;
if (firstPage >= m_pages.size())
return;
if (firstPage == -1)
firstPage = 0;
int lastPage = m_printer->toPage() - 1;
if (lastPage == -1 || lastPage >= m_pages.size())
lastPage = m_pages.size() - 1;
int numPages = lastPage - firstPage + 1;
for (int i = 0; i < m_printer->numCopies(); ++i) {
for (int j = 0; j < numPages; ++j) {
if (i != 0 || j != 0)
m_printer->newPage();
int index;
if (m_printer->pageOrder() == QPrinter::FirstPageFirst) {
index = firstPage + j;
} else {
index = lastPage - j;
}
printPage(painter, m_pages.at(index), index + 1);
}
}
}
(m_pages is a list of pagination data I have built). This code is from "C++ GUI Programming with QT4", Blanchette and Summerfield, 2008.


Are these bugs in the QPrintPreviewDialog?
No, I don't think so.

wbt_ph
28th July 2009, 03:26
Chrisw67:

Thank you for your reply.

If closing the print dialog (which also closes the print preview dialog) is normal, how can you programatically change the closing of print to dialog so it does not close the print preview dialog?

If you have to get the page ranges from qprinter, do you have to repaint or redisplay print preview dialog again?

Wilbert

ChrisW67
1st August 2009, 00:58
Sorry, been off maintaining a VB6 monstrosity for a few days...
If closing the print dialog (which also closes the print preview dialog) is normal, how can you programatically change the closing of print to dialog so it does not close the print preview dialog?
This behaviour is fairly normal when you press Print in a preview even in non-Qt circles. I think to get other behaviour you will have to make your own print preview dialog using QPrintPreviewWidget.

If you have to get the page ranges from qprinter, do you have to repaint or redisplay print preview dialog again?

The Qt code will call paintRequested() as required. In my experience, it gets called once when the dialog is first created (all pages), and once when Print is pressed: different printer object each time, and potentially different from/to page if that's what the user requests on the way through the QPrintDialog.

wbt_ph
1st August 2009, 07:41
ChrisW67:

Thank you for your help. :)

Wilbert