Why do you inherit QSqlQueryModel if you don't use it?Originally Posted by Caius Aérobus
Why do you inherit QSqlQueryModel if you don't use it?Originally Posted by Caius Aérobus
Hello,
thanks for your help, I did not note that QSqlQueryModel was not editable. So if I replace it by QStandardItemModel it works BUT it does not work with QAbstractTableModel. Does it mean that QAbstractTableModel. is also not editable?
Now I have another problem: I have the same model visualized by two views: a table and a graphic. I can edit the values in the table and I would like the graphic be updated accordingly each time I change a value. I expected that the Model/View model does this automatically, that is when a view is connected to a model by the setModel() function, the dataChanged() signal be automatically connected to the appropriate slot of all the views, which does not seem to be how it is handled. Any solution ?
QAbstractTableModel is only an interface to any kind of a tabular model.Originally Posted by Caius Aérobus
Provided that you have implemented your model properly, it should happen automatically.Originally Posted by Caius Aérobus
void QAbstractItemModel::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ) [signal]
This signal is emitted whenever the data in an existing item changes. The affected items are those between topLeft and bottomRight inclusive (of the same parent).
Note that this signal must be emitted explicitly when reimplementing the setData() function.
This signal is properly emitted in my model:
bool
vadTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid() && role == Qt::EditRole) {
this->table[index.row()*C+index.column()] = value.toInt();
emit dataChanged(index, index);
return TRUE;
}
return FALSE;
}
but the question is: which slot of the QAbstractItemView subclass is this signal connected to?
because I have to overwrite this slot code to handle the modifications properly.
This one, I guess:Originally Posted by Caius Aérobus
void QAbstractItemView::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ) [virtual protected slot]
This slot is called when items are changed in the model. The changed items are those from topLeft to bottomRight inclusive. If just one item is changed topLeft == bottomRight.
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));
}
My problems have been solved simply by adding the following line:
setDirtyRegion(viewport()->rect());
Regards.
This should be something like:Originally Posted by Caius Aérobus
Qt Code:
void { update( rect ); }To copy to clipboard, switch view to plain text mode
Bookmarks