Important: Please read the Qt Code of Conduct -

Change cell contents before editing QTableWidget cell?

  • If the user double-clicks on a cell, it is the current contents of the cell that are what is used in the editing box within that cell.

    Is there a way for me to replace the text in the cell just after the double click and just before the cell enters editing mode?

  • @Publicnamer Use a delegate:

    class Delegate: public QStyledItemDelegate{
        using QStyledItemDelegate::QStyledItemDelegate;
        void setEditorData(QWidget *editor, const QModelIndex &index) const{
            if(QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor)){
    tableWidget->setItemDelegate(new Delegate);

Log in to reply