//mytable.cpp
#include <QtGui/QApplication>
#include <QtGui/QMainWindow>
#include <QtGui/QColor>
#include <QtGui/QBrush>
#include "mytable.h"
}
QBrush brush
( QColor(0,
150,
0)/*, Qt::LinearGradientPattern*/);
painter->fillRect(0,0, _size.width(), 20, brush );
painter->fillRect(0,0, 30, _size.height() , brush);
painter
->setPen
(QColor(0,
0,
0));
for( int x = 30; x<= _size.width();x+=80 ) {
painter->drawLine( x, 0, x, _size.height() );
}
for( int y = 20; y <= _size.height(); y+=20){
painter->drawLine(0, y, _size.width(), y );
}
}
/*void mytable::drawHeaders( QPainter* painter, QSize _size ) {
}*/
int main( int argc, char** argv) {
w.setGeometry(0,0,600,600);
mytable table( &w );
table.setGeometry(0,0,600,600);
w.show();
return app.exec();
}
//mytable.cpp
#include <QtGui/QApplication>
#include <QtGui/QMainWindow>
#include <QtGui/QColor>
#include <QtGui/QBrush>
#include "mytable.h"
mytable::mytable( QWidget* parent) : QWidget( parent ) {
}
void mytable::paintEvent( QPaintEvent* event ) {
QPainter* painter=new QPainter(this);
QSize _size = size();
QBrush brush( QColor(0,150,0)/*, Qt::LinearGradientPattern*/);
painter->fillRect(0,0, _size.width(), 20, brush );
painter->fillRect(0,0, 30, _size.height() , brush);
painter->setPen(QColor(0,0,0));
for( int x = 30; x<= _size.width();x+=80 ) {
painter->drawLine( x, 0, x, _size.height() );
}
for( int y = 20; y <= _size.height(); y+=20){
painter->drawLine(0, y, _size.width(), y );
}
}
/*void mytable::drawHeaders( QPainter* painter, QSize _size ) {
}*/
int main( int argc, char** argv) {
QApplication app( argc, argv );
QMainWindow w;
w.setGeometry(0,0,600,600);
mytable table( &w );
table.setGeometry(0,0,600,600);
w.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
//mytable.h
#ifndef MYTABLE_H
#define MYTABLE_H
#include <QtGui/QWidget>
#include <QtGui/QPainter>
public:
protected:
};
//mytable.h
#ifndef MYTABLE_H
#define MYTABLE_H
#include <QtGui/QWidget>
#include <QtGui/QPainter>
class mytable : public QWidget {
public:
mytable(QWidget*);
protected:
void paintEvent( QPaintEvent* );
void drawHeaders(QPainter*, QSize );
};
To copy to clipboard, switch view to plain text mode
Bookmarks