1 | /****************************************************************************
|
---|
2 | ** $Id: gridview.cpp 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
|
---|
5 | **
|
---|
6 | ** This file is part of an example program for Qt. This example
|
---|
7 | ** program may be used, distributed and modified without limitation.
|
---|
8 | **
|
---|
9 | *****************************************************************************/
|
---|
10 |
|
---|
11 | #include <qapplication.h>
|
---|
12 | #include <qgridview.h>
|
---|
13 | #include <qpainter.h>
|
---|
14 |
|
---|
15 | // Grid size
|
---|
16 | const int numRows = 100;
|
---|
17 | const int numCols = 100;
|
---|
18 |
|
---|
19 | class MyGridView : public QGridView
|
---|
20 | {
|
---|
21 | public:
|
---|
22 | MyGridView() {
|
---|
23 | setNumRows( ::numRows );
|
---|
24 | setNumCols( ::numCols );
|
---|
25 | setCellWidth( fontMetrics().width( QString("%1 / %2").arg(numRows()).arg(numCols())));
|
---|
26 | setCellHeight( 2*fontMetrics().lineSpacing() );
|
---|
27 | setCaption( tr( "Qt Example - This is a grid with 100 x 100 cells" ) );
|
---|
28 | }
|
---|
29 |
|
---|
30 | protected:
|
---|
31 | void paintCell( QPainter *p, int row, int col ) {
|
---|
32 | p->drawLine( cellWidth()-1, 0, cellWidth()-1, cellHeight()-1 );
|
---|
33 | p->drawLine( 0, cellHeight()-1, cellWidth()-1, cellHeight()-1 );
|
---|
34 | p->drawText( cellRect(), AlignCenter, QString("%1 / %1").arg(row).arg(col) );
|
---|
35 | }
|
---|
36 | };
|
---|
37 |
|
---|
38 | // The program starts here.
|
---|
39 | int main( int argc, char **argv )
|
---|
40 | {
|
---|
41 | QApplication app( argc, argv );
|
---|
42 |
|
---|
43 | MyGridView gridview;
|
---|
44 | app.setMainWidget( &gridview );
|
---|
45 | gridview.show();
|
---|
46 | return app.exec();
|
---|
47 | }
|
---|