How to get index of a cell in QTableWidget?
<p>I created a table widget and added a contextmenu to it. When I right click the cell,I want to get a file directory and put it into the cell. I've got the directory and pass it to a variable, but i failed to display it in the cell,because I can't get the index of the cell.How to get index of a cell in QTableWidget? Is there any orther method to figure out this qusstion? I'm using Python and PyQt5.</p>

<p><a href="http://i.stack.imgur.com/gwqxR.jpg" rel="nofollow">enter image description here</a></p>

<pre><code>@pyqtSlot()
def on_actionAddFolder_triggered(self):
    # TODO: Open filedialog and get directory
    filedir = str(QFileDialog.getExistingDirectory(self, "Select Directory"))
    return filedir

@pyqtSlot(QPoint)
def on_tableWidget_customContextMenuRequested(self, pos):
    # TODO: get directory and display it in the cell
    x = self.tableWidget.currentRow
    y = self.tableWidget.currentColumn

    RightClickMenu = QMenu()
    AddFolder = RightClickMenu.addAction('Add Folder')
    FolderAction = RightClickMenu.exec_(self.tableWidget.mapToGlobal(pos))
    if FolderAction == AddFolder:
        NewItem = QTableWidgetItem(self.on_actionAddFolder_triggered())
        self.tableWidget.setItem(x,y, NewItem)
</code></pre>

<p>hahaha, I find the mistake!</p>

<pre><code>x = self.tableWidget.currentRow
y = self.tableWidget.currentColumn
</code></pre>

<p>replace these two lines</p>

<pre><code>x = self.tableWidget.currentRow()
y = self.tableWidget.currentColumn()
</code></pre>

<p>then it works.</p>

python pyqt5 qtablewidget