1) I am using setIndexWidget() to display checkboxes in the 4th column and my code is working fine. Is it ok or should i use QItemDelegate to add checboxes?
According to my experience with the model/view,If you use delegate, you would change the model either.
2) Currently the QTableView displays data directly received from the model (database). But suppose, i want to format the data received from the model before displaying on the QTableView, how can i do it? For e.g. suppose the "time" field is stored as seconds in the database and i want to display it in "minutes:seconds" in the QTableView, how can i do that?
you can write the data() function in the model like this
if (role == Qt::DisplayRole)
{
if(index.column() == column_time)
{
//seconds is the "time" field stored value
int min = seconds/60;
int sec = seconds%60;
return QString(%1
:%2
).
arg(min
).
arg(sec
);
}
//.......
}
if (role == Qt::DisplayRole)
{
if(index.column() == column_time)
{
//seconds is the "time" field stored value
int min = seconds/60;
int sec = seconds%60;
return QString(%1:%2).arg(min).arg(sec);
}
//.......
}
To copy to clipboard, switch view to plain text mode
3) I want to do custom drawing in the "tracks" field, for e.g. the currently playing track might have an icon next to the track name. How to do that?
also in the data() func
Make a QIcon,return it when role == Qt:: DecorationRole
Bookmarks