The good news is, report printing already works great in our new accounting software. It went much faster than expected. But, there are complications. Here’s why.
Everything visible in the current Goldenseal is handled the same way. Layouts have a list of fields, buttons, text and graphic objects. Each of those has a size and position. That way our code knows exactly where to draw them on the screen or on paper. Layout data is mostly a bunch of numbers.
So far, we have used the same approach for TurtleSoft Pro.
Last week our staff wrote code to print from our current report layouts. It didn’t work. The print dialog ran OK, but nothing printed. All attempts to fix it failed.
It was time to get help. Any sample projects to start with? Nope, no examples at all for printing. Any info on Qt Forum or Stack Overflow? Sure, there were a dozen posts already, asking how to print QTableWidget (the parent for our report tables). We aren’t the first with the problem.
There were answers, but not what we wanted. Some said to use QTextEdit (it’s similar to Mac TextEdit or Windows NotePad). Others suggested QWebEngine (a built in web browser). None explained how to print tables directly. All the solutions moved data into some other format before printing.
We finally found code to print some other types of QWidget (the parent of all the above). That was a good start. We ran it. It printed OK on Windows, but did nothing on the Mac. Aha! That’s why we also failed. Qt has other problems that only happen on Macs, so it’s not a surprise. Problem is, we need to support both platforms.
As a work-around, QTextEdit seemed possible. It also would be good for contracts and other formatted text. So we gave it a whirl for reports. End result: they look good, and they print great.
QTextEdit is almost a magic bullet. Printing is a snap, with no extra futzing at all. It even handles page breaks properly for long tables. We spent weeks on that little detail in Goldenseal: counting pixels so text wouldn’t split in the middle. Fonts are surprisingly difficult.
The problem is that QTextEdit acts like a word processor, not a graphics layout program. It doesn’t put things at exact pixel locations. Instead, everything flows with the text.
That’s not so bad for reports. Most are simple. We probably can get all of them looking pretty decent. Printed forms will be a bigger problem. Those have boxes, logos and funkier layouts. We haven’t worked with QTextEdit enough yet to know how well it will handle them. If the built-in features are not enough, programmer tricks may help. We can insert transparent objects to space things, maybe.
There’s also a bigger problem. How will users customize QTextEdit-based reports and forms in the Layouts panel? Right now you drag a field around, and it sets the position and size. QTextEdit doesn’t roll that way. In fact, it is downright weird. You add things to it with an imaginary cursor. Almost as if you clicked, then typed or pasted stuff by hand. How do we make a user interface for that? How do we store the data?
It’s a real dilemma. Life will be so much better if Qt handles the printing for us. There are so many ways to go wrong. However, the extra coding and design time may wipe out any time savings. Or we may just have mediocre printed forms.
For now, our staff will keep fiddling with QTextEdit, but also move on to other parts of the accounting software. Better to ease into a decision gradually. Maybe we can find the secret to printing tables directly.
Dennis Kolva
Programming Director
TurtleSoft.com