Yes, I have read this in the doc and below is my code BUT:
- if I iconize the window and then deiconize it, it works and the changes in coordinates appear, which means that the paintEvent() is properly handled,
- but if I change the coordinates in the table view, the coordinates are really changed in the model but the graphic is not updated, and this message appears:
QPainter::begin: Widget painting can only begin as a result of a paintEvent
QPainter::setWindow(), painter not active
I really do not understand how it works! please help!
void
vadControlPolygon::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
this->paint();
}
void
vadControlPolygon:aintEvent(QPaintEvent *event)
{
this->paint();
}
void
vadControlPolygon:aint()
{
QPainter painter(this->viewport());
painter.setWindow(0, 0, 100, 100);
QStyleOptionViewItem option;
this->polygon.setPoints(3,
this->model()->data(this->model()->index(0, 0)).toInt(),
this->model()->data(this->model()->index(0, 1)).toInt(),
this->model()->data(this->model()->index(1, 0)).toInt(),
this->model()->data(this->model()->index(1, 1)).toInt(),
this->model()->data(this->model()->index(2, 0)).toInt(),
this->model()->data(this->model()->index(2, 1)).toInt()
);
painter.drawPolygon(this->polygon);
for (int i=0 ; i<3 ; i++)
this->itemDelegate()->paint(&painter, option, this->model()->index(i, 0));
}
Bookmarks