How customize items of ModelView?
Hello,
I'm french, sorry for my english.
I have a QSqlTableModel and a QTableView.
I want to customize items in my tableView.
Exemple, change the background color of a selected items with values 69:
Code:
if ( model->data(id,Qt::DisplayRole) == 69 )
id->setBackground ( pink) ..... //SOMETHING THAT
Or , I want an icons near items with values = 69.
Re: How customize items of ModelView?
Quote:
Originally Posted by
istdasklar
Exemple, change the background color of a selected items with values 69:
Code:
if ( model->data(id,Qt::DisplayRole) == 69 )
id->setBackground ( pink) ..... //SOMETHING THAT
Subclass QSqlTableModel and reimplement QAbstractItemModel::data():
Code:
QVariant MySqlTableModel
::data(const QModelIndex
& index,
int role
) const {
if (role == Qt::BackgroundRole && val == 69)
{
}
return val;
}
Quote:
Or , I want an icons near items with values = 69.
Similar approach works. Use QModelIndex::sibling() to test sibling items' values.
Re: How customize items of ModelView?
Another possibilities are to use a proxy model that will do that (reimplementing data() as suggested) or a custom item delegate that will paint the item in a different way (changing the background colour or adding an icon).
Re: How customize items of ModelView?
if instead of the QTableView would be a QListView what are the posibilities to change an item position ?
for example, when the mode in the list is Free you can move the items around in the widget so this tells me that items can be placed in a different position.
what i want to achieve to make all the items in a QListView \ QListWidget to be displayed at an offset from the default position ( i want to make them appear more to the right and down)
{ anwers to this post were moved to: custom painting in QListWidget }