Solved How add overwriteMode in QTableWidget.
-
I need overwriteMode in QTableWidget. This function contains in QPlainTextEdit. How to add this in QTableWidget?
-
@Anton-Shelenkov
Editor widgets in itemviews are mostly QLineEdit widgets, which do not have such a property.You can try to create a QPlainTextEdit widget as editor by subclassing QStyledItemDelegate:
QWidget* MyDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const { QPlainTextEdit* editor = new QPlainTextEdit( parent ); editor->setGeometry( option.rect ); editor->setPlainText( index.data().toString() ); editor->setOverwriteMode( true ); return editor; } void MyDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const { if( QPlainTextEdit* edit = qobject_cast<QPlainTextEdit*>(editor) ) { edit ->setPlainText( index.data().toString() ); } } void MyDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const { if( QPlainTextEdit* edit = qobject_cast<QPlainTextEdit*>(editor) ) { model->setData( index, QVariant::fromValue<QString>(edit->toPlainText()) ); } }
(untested)
-
@raven-worx Thanks, your solution work, but in qtableWidget adding PlainText Edits and it work incorrectly because it contains some lines,how to correct this problem?
-
@Anton-Shelenkov
Hi
Can you explain a bit more what is wrong with MyDelegate ?
In what way does it work incorrectly and what do you mean with "some lines" ?To work correctly, what should it do ?
-
@mrjj Default qtableWidgetItem have only one row.
In you solution in every QTableWidgetItem added QPlainTextEdit and when i press enter in TableWidgetItem is added new row and is added scrolbar. I want save tableWidgetItem behavior like lineEdit or default item. -
@Anton-Shelenkov
try addingsetMaximumBlockCount(1)
to the created QPlainTextEdit editor