{
Q_OBJECT
public:
{ m_parent = parent; }
QWidget* createEditor
( QWidget* parent,
const QStyleOptionViewItem
& option,
const QModelIndex& index ) const;
private slots:
void commitAndCloseEditor( void );
private:
};
const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
if ( index.column() == COL_Name )
{
lineEdit->setMaxLength( DEVICE_NAME_MAX );
connect( lineEdit, SIGNAL( returnPressed() ),
this, SLOT( commitAndCloseEditor() ) );
connect( lineEdit, SIGNAL( editingFinished() ),
this, SLOT( commitAndCloseEditor() ) );
return lineEdit;
}
else
}
void DMXTableCellDelegate::commitAndCloseEditor( void )
{
QLineEdit* editor
= qobject_cast<QLineEdit
*>
( sender
() );
emit commitData( editor );
qDebug( "emit closeEditor(): %s", editor->text().toAscii().data() );
}
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 );
}
To copy to clipboard, switch view to plain text mode
Bookmarks