Skip to content

Better support for CUPS features in Qt 5.11

During the last couple of months KDAB engineers have been working on improving CUPS printing support for Linux in Qt.

This work has been sponsored by the LiMux project, a big thank you to them for allowing us to spend time improving Qt :).

We started in early December with a series of small commits cleaning up some code, removing some code that was never called [1] and merging several small functions so the code flow is easier to understand and increases maintainability [2][3][4][5][6].

Our big goal was reviving the Advanced options tab that was present in the first versions of Qt 5 but was removed due to usability concerns [7]. Unfortunately this meant that support of advanced options like automatic stapling (see a quirky video of that here: [8]) was lost.

In the Linux world those advanced options are exposed through CUPS [9] and its support for PPD [10] files. The interesting feature of PPD files is that they have a way to describe not only the options but also how they should be grouped, so you can build an automatic UI on top of it relatively easily.

So working towards the goal we started adding a way to be able to access the PPD structures through the QPrintDevice and its Linux backend (QPpdPrintDevice) [11] [12].

Once that was in, we were in a position to restore the old code (improved thanks to code review) to show the Advanced CUPS options in the printing dialog [13]. The code basically traverses the PPD structures returned by CUPS and creates a model containing all the options. Then this model is plugged into an editable tree view. As said previously, one of the reasons it was removed was that some options were shown in two different places creating confusion for the user. That was solved easily through a blacklist, meaning that important options, like the Page Size, that already have their own space in the user interface, would not be shown in the advanced options tab.

PPD files also have a way of describing conflicts between various options, for example, you can’t print on Photo quality unless you’re using Photo paper. The initial code commit didn’t fully  implement this correctly so we had to fix it [14].

Another usability problem the print dialog had is that it was a bit confusing how much of the state it kept, depending on which order you clicked Ok/Cancel and opened/closed it.  Some of the settings would or would not be stored, so we also fixed that 🙂 [15][16].

Not strictly related to PPD and the advanced CUPS options, is a fix we did regarding the handling of Custom page sizes. Printers can define their own page sizes and the support for that was broken, so since we were going through the code, we also contributed a fix for it [17].

Going back to the Advanced options improvements, we added support for Installable Options [18][19]. Those are some options which basically say, if the user installed some add-ons to their printer like a duplexer or stapler, that enables some of the Advanced options to actually be selectable. For that we also had to contribute a fix to CUPS itself [20] to fix the reported conflicting options when Installable Options are involved, so make sure you’re using CUPS >= 2.3 once it is released, or apply that patch to CUPS manually if you use a printer with Installable Options.

The last change we did for the Advanced tab was to make sure the text that comes from the PPD to describe the options is shown in the correct language (if your PPD has multi language support) [21].

One more feature we implemented in the Qt CUPS printing dialog is arbitrary range printing [22]. Previously one could only say “Print from page 3 to 5”, but not “Print page 1, then from 3 to 5 and then page 11”. This feature has been implemented in Qt itself, so applications don’t need to support it explicitly. Any application that uses the Qt print dialog will gain support for this feature “automagically”!

All these improvements will be released with Qt 5.11. We will soon start to work on some more improvements and bugfixes for the Qt Linux printing dialog for Qt 5.12. Stay tuned!

About KDAB

KDAB is a consulting company offering a wide variety of expert services in Qt, C++ and 3D/OpenGL and providing training courses in:

KDAB believes that it is critical for our business to contribute to the Qt framework and C++ thinking, to keep pushing these technologies forward to ensure they remain competitive.


Categories: KDAB Blogs / KDAB on Qt / Qt

15 thoughts on “Better support for CUPS features in Qt 5.11”

  1. Funny, I was just having a discussion about printing on Linux with some colleagues. I have a brother printer at home, and managing that is a PITA: Printing from command line works, printing from QT applications doesn’t: even though the printer is available in the print dialog, the job never shows up in the queue. Managing printers via CUPS is unreliable at best or simply doesn’t work at all. Jobs often get stalled for no apparent reason, settings are sometimes forgotten and sometimes remembered between print sessions, there’s no indication of toner levels (don’t know who’s to blame)…..

    Well, enough with the rant, my actual intention of writing was to thank you for looking into improving printing on Linux!

    1. >there’s no indication of toner levels (don’t know who’s to blame)…..

      Blame your printer driver, the feature is there for like 10 years and KDE print-manager do display when the driver provides such info.

  2. Actually me thinks (just my 2 cents): it’s a shame that the once-has-been-there functionality vanished with the transition from Qt4 to Qt5. Of course it’s easy to just state, that this is functionality which has to be provided by the underlying OS… Windows and MacOS do in fact provide this but on Linux it’s different. To be fair at that time the discussion was going on to develop a “Linux common print dialogue” (by the way: what came out of this?) which seems to have never materialized.
    Still after some *years* Qt was just neglecting this issue which gave the impression that “Linux” was not a first-class citizen anymore… Thanks for (again) providing this much needed functionality.

  3. Thank you very much; it’s really appreciated!

    With the fixes above is it now possible again to have multiple pages per sheet (like 2×1) and print only even or odd page sets?

    In previous Qt 5 it worked (so my printer is definitely capable of this) but Qt 5.10 now says “Options ‘Pages Per Sheet’ and ‘Page Set’ cannot be used together. Please turn one of those options off.”

    1. The option to print more pages in one sheet is there since a few releases, i suggest if it doesn’t work you should open a bug.

      1. Yes, of course it’s possible since years. But is it possible again to print multiple pages AND print only even or odd page sets?

        1. I don’t know, i didn’t work on that, as said, you should file a bug request if it does not work, blog comments are not the proper place to report bugs 🙂

  4. Great report. Great to hear that work on Qt printing functions is progressing. Printing to paper is really ‘old school’ stuff but in user land (and especially in commercial user land) it is still important.
    As a very ordinary user (KDE PV 5.8.7, FV 5.32.0, QtV 5.6.2), with a very ordinary printer (Brother mono laser) the ‘lost’ printing feature that I miss most is ‘persistent “user set” defaults’. The loss of this basic facility particularly affects plain text printing (e.g., txt, csv, html, etc.), where unsuitable default margins, etc., cannot be set by the user and must be reset for each print job, involving a dozen extra keystrokes, not to mention errors, wasted paper and wasted time. The relative complexity (for ordinary users) of the KDEQtCups relationships makes it difficult for such users to make ‘helpful’ bug reports about this missing ‘feature’, thought many (me included) do try. It ‘just worked’ in KDE3 & KDE4, why can’t we have it back in KDE5? Can KDE (katepart), Qt (print), and Cups developers please have a chat about this?

  5. Can you please add support for printing tow or more pages in one sheet?
    It works only from command line right now.

    1. The option to print more pages in one sheet is there since a few releases, i suggest if it doesn’t work you should open a bug.

      1. Yes there but can’t customize it. You can’t for example print 2 pages in fit page size option or 100% page size. These options not available in GUI yet.

        1. Then as said, you should file a bug request, blog comments are not the proper place to report bugs 🙂

  6. Wonderful news. It’s been such a nuisance having to use Gnome apps to print PDFs properly. Thanks for your work!

  7. Great news, thank you so much for providing printing of arbitrary pages! I was waiting for this feature to come back for several years. I also liked to learn that LiMux gave back to the community. That makes its end even sader 🙁

  8. Nice, but possibility to set margins to 0 disappear. Now, there is default minimal margin, probably in “input policy” for input widget setted to 4.1 mm. Need “Print 100 % size of document” capability in okular for printing drawings from pdf. Some printings must be accurate in size, no matter, if some free area around is out of paper. (No, nothing is out of paper, there are enough space around draving to print it in 100 % of size.)

Leave a Reply

Your email address will not be published.