Hi guys,
I have a QTableView with four columns. I reimplement the virtual method data( ) to align text the cells. So far, so good, but I also want to replace the cells where the value is 0 (zero) for a dash ("-"). While trying to do this, my application compiles correctly but gives an error of segmentation fault when I open the window.
See the code:
{
if (!idx.isValid())
if (role == Qt::DisplayRole && idx.column() > 0 &&
index(idx.row(), idx.column(), idx.parent()).data().toString() == "0")
{
}
else if (role == Qt::TextAlignmentRole)
{
return int(Qt::AlignCenter | Qt::AlignVCenter);
}
return (v);
}
QVariant TableViewQryModel::data(const QModelIndex &idx, int role) const
{
QVariant v = QSqlQueryModel::data(idx, role);
if (!idx.isValid())
return QVariant( );
if (role == Qt::DisplayRole && idx.column() > 0 &&
index(idx.row(), idx.column(), idx.parent()).data().toString() == "0")
{
return QVariant("-");
}
else if (role == Qt::TextAlignmentRole)
{
return int(Qt::AlignCenter | Qt::AlignVCenter);
}
return (v);
}
To copy to clipboard, switch view to plain text mode
Thanks,
Marcelo E. Geyer
Bookmarks