wysota, thanks for helping me with this.
Since I inherited the QTableWidget, release deadlines require me to continue its use, although from everything I've read I really need a QTableView. Since I'm already using a delegate to handle other table cell validation it would seem to make sense to explore the setModelData() route.
Does something like this appear appropriate (provided I don't mess up the validation code
)?
const QModelIndex& index ) const
{
if ( index.column() == COL_Name )
{
QLineEdit* lineEdit
= qobject_cast<QLineEdit
*>
( editor
);
if ( lineEdit != NULL && !lineEdit->text().isEmpty() )
{
QString sValidStr
= lineEdit
->text
();
// validate will return true if the string was modified
if ( validate( sValidStr ) == true )
{
// update the model with the modified string
model->setData( index, sValidStr );
return;
}
}
}
// validate did NOT modify the string
}
void DMXTableCellDelegate::setModelData( QWidget* editor, QAbstractItemModel* model,
const QModelIndex& index ) const
{
if ( index.column() == COL_Name )
{
QLineEdit* lineEdit = qobject_cast<QLineEdit*>( editor );
if ( lineEdit != NULL && !lineEdit->text().isEmpty() )
{
QString sValidStr = lineEdit->text();
// validate will return true if the string was modified
if ( validate( sValidStr ) == true )
{
// update the model with the modified string
model->setData( index, sValidStr );
return;
}
}
}
// validate did NOT modify the string
QItemDelegate::setModelData( editor, model, index );
}
To copy to clipboard, switch view to plain text mode
Bookmarks