Visualising data from mysql table
For the purpose of visualizing data from a MySQL table, a QTableView is being used in conjunction with a QSqlTableModel. As the intention is not to edit the values then the QTableView is configured with: Is this a good approach in order to prevent editing the data?
Re: Visualising data from mysql table
Yes, but the model remains editable in any view that allows editing. QSqlQueryModel gives you a truly read-only model.
Re: Visualising data from mysql table
Ok, I understand.
I think QSqlTableModel was used because it enables changing the color of items, re-writing the data function.
Code:
{
if ( role == Qt::TextColorRole )
if( (index.column(), index.row()) )
return value;
}
As it doesn't exist a data function for QSqlQueryModel then I suppose I'm in the correct direction. Is there another approach which could be applied in order to attend both requirements, change item color and prevent editing the database?
Thanks for the attention.
Re: Visualising data from mysql table
QSqlQueryModel is a subclass of QAbstractItemModel, so it has a data() method.
Cheers,
_