PDA

View Full Version : PyQt4, QTableView with QLineEdit as a QItemDelegate and selection



mikecrowe
14th January 2010, 04:12
Hi folks,

I'm having a strange problem. I have a grid of QLineEdits, QSpinBoxs, and other controls in a QTableView (see attached image). When I first create the page, every QLineEdit and QSpinBox item is selected.

4129

I have tried things like:



def createEditor(self, parent, option, index):
self.lineEdit = QLineEdit(parent)
self.lineEdit.setValidator(QDoubleValidator(self.l ineEdit))
self.lineEdit.textChanged.connect(self.emitCommitD ata)
self.lineEdit.setText(self.getValue().toString())
self.lineEdit.setAlignment(Qt.AlignVCenter|Qt.Alig nRight)
self.lineEdit.selectAll()
self.lineEdit.setSelection(0, 0)
return self.lineEdit


and



def createEditor(self, parent, option, index):
self.lineEdit = QLineEdit(parent)
self.lineEdit.setValidator(QDoubleValidator(self.l ineEdit))
self.lineEdit.textChanged.connect(self.emitCommitD ata)
self.lineEdit.setText(self.getValue().toString())
self.lineEdit.setAlignment(Qt.AlignVCenter|Qt.Alig nRight)
self.lineEdit.deselect()
return self.lineEdit


to no avail. Also, I considered that it might be something in the QTableView, and have tried even deselecting the items in it too.

If I switch away from the window (alt-tab) and come back, all the text is deselected.

Can anybody point me in the right direction?

Developing on Windows
ActivePython 2.6.2.2
Qt 4.5.1

TIA
Mike

madrich
18th August 2011, 14:13
Hi Mike,

I have the same issue with QT 4.7.3 for c++. Do you have a solution yet?

Best Richard

frankiefrank
6th September 2011, 11:27
Could be related to this bug? I had the same problem with a QSpinBox.
https://bugreports.qt.nokia.com//browse/QTBUG-17348