This example shows
#ifndef _EXAMPLE3_H #define _EXAMPLE3_H #include <qwidget.h> #include <qdbt/qdbtsection.h> class QLabel; class Example3 : public QWidget { Example3( const Example3 & ); void operator=( const Example3 & ); public: Example3( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); ~Example3(); }; class Example3Section : public QdbtSection { Example3Section( const Example3Section & ); void operator=( const Example3Section & ); public: Example3Section( QdbtBaseTabular *parent = 0, const char *name = 0 ); ~Example3Section(); int widthHint() const; int heightHint() const; protected: void drawButtonLabel( QPainter *p ); }; #endif
#include <qapplication.h> #include <qlabel.h> #include <qlayout.h> #include <qmenudata.h> #include <qpainter.h> #include <qpushbutton.h> #include <qstyle.h> #include "example3.h" #include <qdbt/qdbtsection.h> #include <qdbt/qdbttabcell.h> #include <qdbt/qdbttabular.h> const int tableRows = 20; const int tableCols = 8; const int border = 5; Example3Section::Example3Section( QdbtBaseTabular *parent, const char *name ) : QdbtSection( parent, name ) { } Example3Section::~Example3Section() { } int Example3Section::widthHint() const { return fontMetrics().height()+2*border; } int Example3Section::heightHint() const { return fontMetrics().width(text())+2*border; } void Example3Section::drawButtonLabel( QPainter *p ) { QColorGroup g = colorGroup(); p->setPen( g.text() ); p->translate( width()/2+border, height()-border ); p->rotate( -90 ); p->drawText( 0, 0, text() ); p->resetXForm(); if ( hasFocus() ) { #if QT_VERSION >= 300 QRect sr = style().subRect( QStyle::SR_PushButtonFocusRect, this ); style().drawPrimitive ( QStyle::PE_FocusRect, p, sr, g, QStyle::Style_HasFocus ); #else // for Qt-2.3.1 (at least) the focus rect is being draw somehow else... #endif } } Example3::Example3( QWidget *parent, const char *name, WFlags f ) : QWidget( parent, name, f ) { // Set the caption of the window setCaption( "Example 3" ); // The Layout managers QGridLayout *layout = new QGridLayout( this, 2, 1, 5 ); QBoxLayout *buttons = new QBoxLayout( QBoxLayout::LeftToRight ); // create three tables QdbtTabular *tabular = new QdbtTabular( this ); // set the number of row/columns tabular->setDimensions( tableRows, tableCols ); // set the minimum size of the table tabular->setMinimumSize( 200, 200 ); // select cell instead of rows tabular->selectByRow( FALSE ); // set the font of the heading tabular->setHeaderFont( QFont( "helvetica", 16, QFont::Bold ) ); // set the font of the cells tabular->setCellFont( QFont( "helvetica", 12, QFont::Normal ) ); int row, col; // for each column for ( col = 0; col < tableCols; col++ ) { QString head; head.sprintf( "H%d", col ); // set the heading of column `col' Example3Section *section = new Example3Section( tabular ); section->setText( head ); tabular->changeSection( section, col ); // for each row for ( row = 0; row < tableRows; row++ ) { QdbtTableCell cell; QString cellName; cellName.sprintf( "cell (%d,%d)", row, col ); cell.setText( cellName ); cell.setEditable( TRUE ); // set the cell's text tabular->changeCell( &cell, row, col ); } } // make sure all cells fit tabular->fitAll(); // Create the close button QPushButton *close = new QPushButton( "Close", this ); // Set its minimum sizes close->setMinimumSize( close->sizeHint() ); // Add Widgets and layouts to the layout-manager layout->addWidget( tabular, 0, 0 ); layout->addLayout( buttons, 1, 0 ); layout->setColStretch( 0, 1 ); // make the table strechable layout->setRowStretch( 0, 1 ); // Add the Widget to the button layout buttons->addStretch( 1 ); buttons->addWidget( close ); // don't forget to activate the top layout manager layout->activate(); // Let the close button quit the application connect( close, SIGNAL( clicked() ), qApp, SLOT( quit() ) ); // Resize the widget to its minimal size resize( layout->mainWidget()->sizeHint() ); } Example3::~Example3() { } int main( int argc, char **argv ) { QApplication app( argc, argv ); Example3 example; app.setMainWidget( &example ); example.show(); return app.exec(); }