Qt 4: The book

Page 292

10 The Graphics Library “Arthur”

QSize PieWidget::sizeHint() const { return minimumSizeHint(); }

The template function qMax() helps us in doing this. It is able to compare two objects of the same type, provided they both have the smaller-than operator, and it returns the larger element. In the same way, qMin() also exists. The width is determined by the following parameters: the widget height of the square of the pie,5 the longest entry in the hash table, the width of an x, the width of the legend square (fm) and the width of the 2 × 10 pixel–wide margin on both sides of the legend square. We pack the height and width into an instance of QSize and return this.

10.5.3 The Diagram Application In order to use the class, we instantiate the widget, add a few entries with values, and display it. We have already seen the result in Figure 10.6: // piechart/main.cpp #include <QtGui> #include "piewidget.h" int main(int argc, char* { QApplication app(argc, PieWidget w; w.addEntry("Choice 1", w.addEntry("Choice 2", w.addEntry("Choice 3", w.addEntry("Choice 4", w.show(); return app.exec(); }

argv[]) argv); 50); 40); 60); 70);

10.6 Transformations of the Coordinate System Normally a QPainter draws in a neutral, two-dimensional coordinate system. But sometimes it is necessary to manipulate this. Qt includes the QMatrix class for this purpose, which we will first approach theoretically. A QMatrix makes available a 3 × 3 matrix in the form 5

290

With squares, length and width are equal.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.