hannesvdc
24th December 2010, 08:48
Hey,
I'm currently making my own tablewidget because i want to have more than a thousand rows and columns and QTableWidget takes too much memory.
So i started working on it, and this is what i currently have:
//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();
}
//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 );
};
Compiling works fine, but if i run, the widget shows up, but i get the following error
if i resize the widget:
QPixmap::operator=: Cannot assign to pixmap during painting
And this error if i close the widget:
QPaintDevice: Cannot destroy paint device that is being painted
What can i do to solve this errors?
regards, hannesvdc
I'm currently making my own tablewidget because i want to have more than a thousand rows and columns and QTableWidget takes too much memory.
So i started working on it, and this is what i currently have:
//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();
}
//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 );
};
Compiling works fine, but if i run, the widget shows up, but i get the following error
if i resize the widget:
QPixmap::operator=: Cannot assign to pixmap during painting
And this error if i close the widget:
QPaintDevice: Cannot destroy paint device that is being painted
What can i do to solve this errors?
regards, hannesvdc