All You Need is a little Polish

When you write documentation on a daily basis, with very little link to the outside world* beyond the tasks created by our esteemed Support department, you can get lost in your own little world, thinking your documentation is perfect ;)

So if the documentation is perfect, then Qt is perfect, no?

But, I digress (before I get into trouble for making overly optimistic conclusions). To obtain a different perspective, I moonlighted in Support for almost 6 months and realized "There is always room for improvement".

Now one of these improvements came in the form of a question asked by a nice customer: How do you print with Item Views?

This got me thinking. I looked through most of Qt's examples thinking "Surely we have an example that does this." but there was no example with this feature. Digging a little deeper, I realized that Qt did not provide this solution directly. In a perfect world, there would be a big, red, blinky "print()" function in the API. Alas, we do not live in a perfect world.

But, here's a solution I have in mind. It is now part of the Spreadsheet demo, in the next release.

Below is the code I used.


class PrintView : public QTableView
{
Q_OBJECT

public:
PrintView();

public Q_SLOTS:
void print(QPrinter *printer);
};

There is a special PrintView class that inherits QTableView, and here is its implementation:


PrintView::PrintView()
{
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}

void PrintView::print(QPrinter *printer)
{
resize(printer->width(), printer->height());
render(printer);
}

And here's the output.


PrintView

I do plan to find ways to improve this though. So, feedback/other ideas are definitely welcome ;) No brickbats please, I am only human.

You will notice, the Spreadsheet demo's code got a bit of polish, in the process. Nice shiny headers and cpp files were used to make it feel young, hot, and sexy again ;) Can you believe it was shipped in a "main.cpp" file all this while? Shame on us!

P/s - A shout out to Simon and MBM for pushing my clean, innocent *cough* mind in the right direction!

* Last I heard, there were no conferences for poor technical writers.


Blog Topics:

Comments