Originally Posted by
wbt_ph
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);
}
}
}
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);
}
}
}
To copy to clipboard, switch view to plain text mode
(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.
Bookmarks