Hello,
all examples I have found up to now create the painter each time they need it but I would like to be able to design a general drawing class, in which a painter is defined with a numpber of common attributes, and then design subclasses using this commonly defined painter. So I have the general class creator definied as:
vadVisualization::vadVisualization(QAbstractItemMo del *model, vad *app, QWidget *parent,
int xsize, int ysize, char *name, int debug)
: QAbstractItemView(parent)
{
this->setModel(model);
[...]
this->painter = new QPainter(this->viewport());
}
and the specific class paintEvent method defined as:
void
vadControlPolygon:aintEvent(QPaintEvent *event)
{
QAbstractItemView:aintEvent(event);
setDirtyRegion(this->viewport()->rect());
this->painter->begin(this->viewport());
this->painter->setWindow(0, 0, 100, 100);
[...]
this->painter->drawPolygon(this->polygon);
// les sommets
for (int i=0 ; i<3 ; i++)
this->itemDelegate()->paint(this->painter, option, this->model()->index(i, 0));
this->painter->end();
}
but I get the following errors:
QPainter::begin: Widget painting can only begin as a result of a paintEvent
QPainter::begin(): Painter is already active.
You must end() the painter before a second begin()
QPainter::setWindow(), painter not active
QPainter::end: Painter is not active, aborted
QPainter::begin(): Painter is already active.
You must end() the painter before a second begin()
QPainter::setWindow(), painter not active
QPainter::end: Painter is not active, aborted
QPainter::begin(): Painter is already active.
so ok I understand that my painter is already active, which means that I do not need to begin() and end() it, and then I change my code by withdrawing the begin() and end() calls. Then I get the following errors:
QPainter::begin: Widget painting can only begin as a result of a paintEvent
QPainter::setWindow(), painter not active
QPainter::setWindow(), painter not active
QPainter::setWindow(), painter not active
QPainter::setWindow(), painter not active
QPainter::setWindow(), painter not active
QPainter::setWindow(), painter not active
so please coulod anybody explains me how painter are managed by Qt and how to cope with this in my case?
Bookmarks