mclark
26th November 2007, 17:16
While using my custom QItemDelegate, the QLineEdit editor is not always closing. The closeEditor() signal is emitted but the QLineEdit object remains in the QTableWidgetItem.
I am using 4.2.2 and setting the edit triggers using QAbstractItemView::AllEditTriggers.
This happens when I have multiple rows in the table and I click (speed is irrelevant) on the editable items:
Click on row 0, column 1
Click on row 1, column 1
Click on row 2, column 1
repeat
Eventually one of the editors in column 1 will get stuck on, even though the closeEditor() signal was emitted. The qDebug() statement shows the contents of the item where the editor should be closed and is displayed even when the editor does not go away. This state does not allow any other editors to appear in the table, effectively stopping the user from editing any other items.
Has anyone else seen this type of behavior? Any ideas how to prevent this?
class DMXTableCellDelegate : public QItemDelegate
{
Q_OBJECT
public:
DMXTableCellDelegate( QObject* parent = 0 ) : QItemDelegate( parent )
{ m_parent = parent; }
QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option,
const QModelIndex& index ) const;
private slots:
void commitAndCloseEditor( void );
private:
QObject* m_parent;
};
QWidget* DMXTableCellDelegate::createEditor( QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
if ( index.column() == COL_Name )
{
QLineEdit* lineEdit = new QLineEdit( parent );
lineEdit->setMaxLength( DEVICE_NAME_MAX );
connect( lineEdit, SIGNAL( returnPressed() ),
this, SLOT( commitAndCloseEditor() ) );
connect( lineEdit, SIGNAL( editingFinished() ),
this, SLOT( commitAndCloseEditor() ) );
return lineEdit;
}
else
return QItemDelegate::createEditor( parent, option, index );
}
void DMXTableCellDelegate::commitAndCloseEditor( void )
{
QLineEdit* editor = qobject_cast<QLineEdit*>( sender() );
emit commitData( editor );
qDebug( "emit closeEditor(): %s", editor->text().toAscii().data() );
emit closeEditor( editor, QAbstractItemDelegate::EditNextItem );
}
I am using 4.2.2 and setting the edit triggers using QAbstractItemView::AllEditTriggers.
This happens when I have multiple rows in the table and I click (speed is irrelevant) on the editable items:
Click on row 0, column 1
Click on row 1, column 1
Click on row 2, column 1
repeat
Eventually one of the editors in column 1 will get stuck on, even though the closeEditor() signal was emitted. The qDebug() statement shows the contents of the item where the editor should be closed and is displayed even when the editor does not go away. This state does not allow any other editors to appear in the table, effectively stopping the user from editing any other items.
Has anyone else seen this type of behavior? Any ideas how to prevent this?
class DMXTableCellDelegate : public QItemDelegate
{
Q_OBJECT
public:
DMXTableCellDelegate( QObject* parent = 0 ) : QItemDelegate( parent )
{ m_parent = parent; }
QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option,
const QModelIndex& index ) const;
private slots:
void commitAndCloseEditor( void );
private:
QObject* m_parent;
};
QWidget* DMXTableCellDelegate::createEditor( QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
if ( index.column() == COL_Name )
{
QLineEdit* lineEdit = new QLineEdit( parent );
lineEdit->setMaxLength( DEVICE_NAME_MAX );
connect( lineEdit, SIGNAL( returnPressed() ),
this, SLOT( commitAndCloseEditor() ) );
connect( lineEdit, SIGNAL( editingFinished() ),
this, SLOT( commitAndCloseEditor() ) );
return lineEdit;
}
else
return QItemDelegate::createEditor( parent, option, index );
}
void DMXTableCellDelegate::commitAndCloseEditor( void )
{
QLineEdit* editor = qobject_cast<QLineEdit*>( sender() );
emit commitData( editor );
qDebug( "emit closeEditor(): %s", editor->text().toAscii().data() );
emit closeEditor( editor, QAbstractItemDelegate::EditNextItem );
}