QTextDocument::print ignores # of copies from QPrintDialog
So I have a simple print method that will print HTML content stored in a QTextDocument. It works reasonably well, but when I print it, it ignores the number of copies set by the QPrintDialog
I have the following code:
- QPrinter printer;
- printDialog.setOptions(flags);
- printer.isValid()) {
- QTextDocument doc;
- doc.setHtml(mHtml);
- doc.print(&printer);
- }
where mHtml is a QString that contains the HTML content.
Now, on the QPrintDialog that pops up, I set the number of copies to 2, but when I click “Print”, it only prints 1 copy.
I could find nothing in the documentation for QPrinter, QPrintDialog, QTextDocument, or the article Printing With Qt [doc.qt.nokia.com] mention anything about having to manually handle multiple copies.
So, has anyone bumped into this before? Do I need to manually handle multiple copies? If so, any suggestions on how to handle the collate option?
10 replies
Someone help me out here, please.
I’ve dug through the source code for QTextDocument::print(), and the behavior I was expecting seems to only happen if the printer’s supportsMultipleCopies [doc.qt.nokia.com] function returns false.
(taken from qtextdocument.cpp, lines 1790 – 1796)
- if (printer->collateCopies() == true){
- docCopies = 1;
- pageCopies = printer->supportsMultipleCopies() ? 1 : printer->copyCount();
- } else {
- docCopies = printer->supportsMultipleCopies() ? 1 : printer->copyCount();
- pageCopies = 1;
- }
Does this mean that it is normally expected for my application to manually handle the printing of multiple copies?
Can anyone confirm this, please?
Well, according to the documentation [doc.qt.nokia.com] “On most systems this function will return true. However, on X11 systems that do not support CUPS, this function will return false. That means the application has to handle the number of copies by printing the same document the required number of times.” (emphasis mine)
Actually, what I believe the above code is doing is handling this case for you (that is, when QPrinter won’t handle multiple copies, QTextDocument will do it for you). So it would appear that the problem is something like your printer says it supports multiple copies, but when it’s told to print them it’s not doing so.
Well, I wouldn’t say “no” closer: you know where the problem isn’t now, that’s a start. I’d start putting in some more breakpoints in between the call to print() and the call to setProperty(), in places where you expect the code to go, and try to figure out at what point it’s deciding not to pass the copy count onto the printer driver.
You must log in to post a reply. Not a member yet? Register here!

