As a relatively new Trolltech employee (this is my first post!), I was thrown into Qt’s printing framework, with the hopes of improving some of the long standing issues.
One of the problems with printing using Qt today isn’t actually printing itself, but rather information about printers. The current framework is very opaque; typically a programmer just has to set a printer name on a QPrinter object, start painting and hope that it reaches some printer out there. The only way to reliably select a printer is by using QPrintDialog and let the user select it there. However, the programmer cannot influence the appearance or behavior of the dialog, nor can he/she automate the choice of printers.
With this in mind, we started working on a new class, QPrinterInfo, whose task is to provide information about the printers that are installed on the system. Some API decisions are yet to be made, but users will be able to query for installed printers, which printer is the default, and what paper sizes each printer supports.
Here is an example of how you can list the printers on a system:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDialog dialog;
QLayout* layout = new QGridLayout;
QPushButton* ok = new QPushButton(QLatin1String("OK"));
QLabel* text = new QLabel;
layout->addWidget(text);
layout->addWidget(ok);
dialog.setLayout(layout);
QList<QPrinterInfo> printerList = QPrinterInfo::availablePrinters();
QString printers("Printers:\n");
for (int c = 0; c < printerList.size(); ++c) {
printers += printerList[c].printerName();
printers += QLatin1String("\n");
}
printers += "\nDefault:\n";
printers += QPrinterInfo::defaultPrinter().printerName();
text->setText(printers);
QObject::connect(ok, SIGNAL(clicked()), &dialog, SLOT(accept()));
dialog.show();
dialog.exec();
return 0;
}

3 Responses to “Printer information support”
Things it’d be good to know include:
- If the printer is raw PostScript passthrough capable (and an option to use that - using RAW mode on UNIX/Mac OS X where CUPS is available, and using the native passthrough APIs on win32)
- Duplex capable
- Colour capable
- Get ICC profile (if available) from system
- Any printer-specific custom paper sizes, not just a paper size enum
- If available, maximum printable area
- If available, maximum detail (PPI/DPI)
What I should’ve said first in my previous comment is “That’s great - it looks handy and should be quite helpful.” Which is quite true. It’d be very nice indeed if apps didn’t have to have their own platform-specific printing code for everything.
Is there anything being done to speed up QPrinter. It seems to take a lot of time to execute.