Question

In a dialog, I have a table-widget and multiple line edits. The user clicks the mouse in one of the line-edits, and then double-clicks on an item in the table-widget. In the double-click slot (self.myfunct), how do I determine which line-edit had the cursor, so I can set that table-item name in the right line-edit?

self.connect(self, QtCore.SIGNAL('itemDoubleClicked(QTableWidgetItem *)'), self.myfunct)

Some wrappers are present over PyQt4 so I can't paste the code directly.

screenshot1

Was it helpful?

Solution

You can achieve what you want by keeping a reference to the last QLineEdit selected. Initialize self.current_line_edit to your first QLineEdit, then connect the editingFinished signal of each QLineEdit to your custom slot.

def __init__(self, parent=None):
    ...
    ...
    self.current_line_edit = self.line_edit_1
    self.tablewidget.itemDoubleClicked.connect(self.onDoubleClick)
    self.line_edit_1.editingFinished.connect(self.onChangeLineEdit)
    self.line_edit_2.editingFinished.connect(self.onChangeLineEdit)
    self.line_edit_3.editingFinished.connect(self.onChangeLineEdit)
    ...
    ...

def onChange(self):
    self.current_line_edit = self.sender()

def onDoubleClick(self, item):
    self.current_line_edit.setText(item.text())
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top