source: trunk/examples/gridview/gridview.cpp@ 10

Last change on this file since 10 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
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
16const int numRows = 100;
17const int numCols = 100;
18
19class MyGridView : public QGridView
20{
21public:
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
30protected:
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.
39int 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}
Note: See TracBrowser for help on using the repository browser.