not displaying old value when editing cell in a QTableWidget
<p>I have a basic QTableWidget, created with this python code:</p>

<pre><code>from silx.gui import qt
app = qt.QApplication([])
qtw = qt.QTableWidget()
qtw.show()
qtw.setColumnCount(8)
qtw.setRowCount(7)
app.exec_()
</code></pre>

<p>The <code>from silx.gui import qt</code> line is just a wrapper that finds out the installed qt wrapper (PyQt4, PyQt5 or PySide) and flattens the qt namespace.</p>

<p>The resulting table has a strange behavior when I edit a cell: as expected, the old text is highligted when I double-click the cell, but the unusual behavior is that the old text remains visible and the new text overlaps with the old one while I'm typing it, until I press enter or I click another cell.</p>

<p>I would like the old text to disappear as soon as I start typing the new one. I know it's possible, because I have an example of program that features a qTableWidget with the behavior I would like to have. </p>

<p>But I cannot find where in that program the cell editing behavior is altered. How can IÂ do this?</p>

<p>Example of "spam" and "eggs" overlayed.</p>

<p>[<img src="http://i.stack.imgur.com/Fx5tO.png" alt="example of &quot;spam&quot; and &quot;eggs&quot; overlayed[1]"></p>

<p>EDIT: the code sample without the wrapper business</p>

<pre><code>from PyQt5.Qt import QApplication, QTableWidget, qVersion
app =QApplication([])
print(qVersion())
qtw = QTableWidget()
qtw.show()
qtw.setColumnCount(8)
qtw.setRowCount(7)
app.exec_()
</code></pre>

<p>With PyQt4, use this import (also remove the <code>print(qVersion())</code> line):</p>

<pre><code>from PyQt4.QtGui import QApplication, QTableWidget
</code></pre>

<p>Generally, edit behavior is controlled via <code>QItemDelegates</code>.  Typically, this is done to provide more advanced editing, or to filter input data or perform some side effects (like update a database) when edits are made.  But you can also use it to just clear the editor presented to the user when editing.</p>

<pre><code>class MyDelegate(QItemDelegate):

    def setEditorData(self, editor, index):
        # Normally, this would set the text of the editor to the current
        # value of the cell.  If you do nothing here, it will be blank.
        editor.clear()

qtw = QTableWidget()
delegate = MyDelegate(qtw)
qtw.setItemDelegate(delegate)
</code></pre>

python qt pyqt qtablewidget