This example shows:
#ifndef _EXAMPLE4_H #define _EXAMPLE4_H #include <qpoint.h> #include <qdbt/qdbttabular.h> class QWidget; class QLabel; class Example4Tabular : public QdbtTabular { Example4Tabular( const Example4Tabular & ); void operator=( const Example4Tabular & ); public: Example4Tabular( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); virtual ~Example4Tabular(); protected: void mouseDoubleClickEvent( QMouseEvent * ); }; class Example4 : public QWidget { Example4( const Example4 & ); void operator=( const Example4 & ); public: Example4( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); virtual ~Example4(); }; #endif
#include <qapplication.h> #include <qlayout.h> #include <qpushbutton.h> #include <qlabel.h> #include <qpixmap.h> #include <qdbt/qdbttabcell.h> #include <qdbt/qdbtintcell.h> #include <qdbt/qdbttextcell.h> #include <qdbt/qdbtcombocell.h> #include <qdbt/qdbtsection.h> #include <qdbt/qdbtselection.h> #include "example4.h" const QColor base( 230, 200, 200 ); Example4Tabular::Example4Tabular( QWidget *parent, const char *name, WFlags f ) : QdbtTabular( parent, name, f ) { QColorGroup cg = colorGroup(); QColorGroup newCg( black, base, base.light(), base.dark(), base, black, base.dark(110) ); setPalette( QPalette( newCg, newCg, newCg ) ); QdbtNoCell defCell; setDefaultCell( defCell ); } Example4Tabular::~Example4Tabular() { } void Example4Tabular::mouseDoubleClickEvent( QMouseEvent *e ) { int rowClicked = findRow( e->y() ); int colClicked = findCol( e->x() ); if ( rowClicked != -1 && colClicked > 0 ) { editCell( rowClicked, colClicked ); } } Example4::Example4( QWidget *parent, const char *name, WFlags f ) : QWidget( parent, name, f ) { // Set the caption of the window setCaption( "Example 4" ); // The Layout managers QGridLayout *layout = new QGridLayout( this, 2, 1, 5 ); QBoxLayout *buttons = new QBoxLayout( QBoxLayout::LeftToRight ); // create three tables Example4Tabular *tabular = new Example4Tabular( this ); // set the number of row/columns tabular->setDimensions( 10, 3 ); // let's test the insertCol function, just for fun. tabular->insertCol( 3 ); // let's test the insertCol function, just for fun. tabular->insertRow( 5 ); // set the minimum size of the table tabular->setMinimumSize( 100, 100 ); // select cell instead of rows ... tabular->selectByRow( FALSE ); // ... and just one of them tabular->setMultiSelect( 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 ) ); // Load the folder pixmap (No error checking!) QPixmap folder; folder.load( "folder3d.xpm" ); QdbtSection *section; section = tabular->section( 0 ); section->setResizable( FALSE ); section = tabular->section( 1 ); section->setText( "Left" ); section = tabular->section( 2 ); section->setText( "Center" ); section->setAlignment( AlignCenter ); section = tabular->section( 3 ); section->setText( "Right" ); section->setAlignment( AlignRight ); QdbtTableCell cell; QdbtTextCell textCell; QdbtIntCell intCell; QdbtComboCell comboCell; QdbtBorderlessComboCell borderlessComboCell; cell.setEditable( FALSE ); // cell.setSelectable(FALSE); textCell.setEditable( TRUE ); // textCell.setSelectable(FALSE); intCell.setEditable( TRUE ); // intCell.setSelectable(FALSE); // first column cell.setAlignment( AlignLeft ); textCell.setAlignment( AlignLeft ); intCell.setAlignment( AlignLeft ); comboCell.setAlignment( AlignLeft ); borderlessComboCell.setAlignment( AlignLeft ); cell.setPixmap( 0 ); cell.setBackground( tabular->colorGroup().base().dark(120) ); cell.setText( "Text only" ); tabular->changeCell( &cell, 0, 0 ); cell.setText( "Pixmap only" ); tabular->changeCell( &cell, 1, 0 ); cell.setText( "Pimap left" ); tabular->changeCell( &cell, 2, 0 ); cell.setText( "Pimap right" ); tabular->changeCell( &cell, 3, 0 ); cell.setText( "Pimap top" ); tabular->changeCell( &cell, 4, 0 ); cell.setText( "Pimap bottom" ); tabular->changeCell( &cell, 5, 0 ); cell.setText( "Text Cell" ); tabular->changeCell( &cell, 6, 0 ); cell.setText( "Integer Cell" ); tabular->changeCell( &cell, 7, 0 ); cell.setText( "Combo Cell" ); tabular->changeCell( &cell, 8, 0 ); cell.setText( "Borderless\nCombo Cell" ); tabular->changeCell( &cell, 9, 0 ); cell.setText( "No Cell" ); tabular->changeCell( &cell, 10, 0 ); cell.setEditable( TRUE ); // second column cell.setBackground( tabular->colorGroup().base() ); cell.setText( "left" ); tabular->changeCell( &cell, 0, 1 ); cell.setText( 0 ); cell.setPixmap( &folder ); cell.setPixmapAlignment( AlignLeft ); tabular->changeCell( &cell, 1, 1 ); cell.setText( "left" ); tabular->changeCell( &cell, 2, 1 ); cell.setPixmapAlignment( AlignRight ); tabular->changeCell( &cell, 3, 1 ); cell.setPixmapAlignment( AlignTop ); tabular->changeCell( &cell, 4, 1 ); cell.setPixmapAlignment( AlignBottom ); tabular->changeCell( &cell, 5, 1 ); tabular->QdbtBaseTabular::changeCell( &textCell, 6, 1 ); tabular->QdbtBaseTabular::changeCell( &intCell, 7, 1 ); tabular->QdbtBaseTabular::changeCell( &comboCell, 8, 1 ); tabular->QdbtBaseTabular::changeCell( &borderlessComboCell, 9, 1 ); // third column cell.setAlignment( AlignCenter ); textCell.setAlignment( AlignCenter ); intCell.setAlignment( AlignCenter ); comboCell.setAlignment( AlignCenter ); borderlessComboCell.setAlignment( AlignCenter ); cell.setText( "center" ); cell.setPixmap( 0 ); tabular->changeCell( &cell, 0, 2 ); cell.setText( 0 ); cell.setPixmap( &folder ); cell.setPixmapAlignment( AlignLeft ); tabular->changeCell( &cell, 1, 2 ); cell.setText( "center" ); tabular->changeCell( &cell, 2, 2 ); cell.setPixmapAlignment( AlignRight ); tabular->changeCell( &cell, 3, 2 ); cell.setPixmapAlignment( AlignTop ); tabular->changeCell( &cell, 4, 2 ); cell.setPixmapAlignment( AlignBottom ); tabular->changeCell( &cell, 5, 2 ); tabular->QdbtBaseTabular::changeCell( &textCell, 6, 2 ); tabular->QdbtBaseTabular::changeCell( &intCell, 7, 2 ); tabular->QdbtBaseTabular::changeCell( &comboCell, 8, 2 ); tabular->QdbtBaseTabular::changeCell( &borderlessComboCell, 9, 2 ); // forth column cell.setAlignment( AlignRight ); textCell.setAlignment( AlignRight ); intCell.setAlignment( AlignRight ); comboCell.setAlignment( AlignRight ); borderlessComboCell.setAlignment( AlignRight ); cell.setText( "right" ); cell.setPixmap( 0 ); tabular->changeCell( &cell, 0, 3 ); cell.setText( 0 ); cell.setPixmap( &folder ); cell.setPixmapAlignment( AlignRight ); tabular->changeCell( &cell, 1, 3 ); cell.setText( "right" ); cell.setPixmapAlignment( AlignLeft ); tabular->changeCell( &cell, 2, 3 ); cell.setPixmapAlignment( AlignRight ); tabular->changeCell( &cell, 3, 3 ); cell.setPixmapAlignment( AlignTop ); tabular->changeCell( &cell, 4, 3 ); cell.setPixmapAlignment( AlignBottom ); tabular->changeCell( &cell, 5, 3 ); tabular->QdbtBaseTabular::changeCell( &textCell, 6, 3 ); tabular->QdbtBaseTabular::changeCell( &intCell, 7, 3 ); tabular->QdbtBaseTabular::changeCell( &comboCell, 8, 3 ); tabular->QdbtBaseTabular::changeCell( &borderlessComboCell, 9, 3 ); tabular->setColumnWidth( 0, tabular->columnWidthHint(0) ); tabular->setColumnWidth( 1, tabular->columnWidthHint(1)+100 ); tabular->setColumnWidth( 2, tabular->columnWidthHint(2)+100 ); tabular->setColumnWidth( 3, tabular->columnWidthHint(3)+100 ); // 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() ); } Example4::~Example4() { } int main( int argc, char **argv ) { QApplication app( argc, argv ); Example4 example; app.setMainWidget( &example ); example.resize( 640, 340 ); example.show(); return app.exec(); }