Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.15.10, 6.3.0, 6.x
-
None
-
Windows 10/11 64BIT, PyQt5 and PyQt6
Description
QTableWidget methods currentRow() and currentColumn() return wrong values when the mouse button is kept pressed (in order to make multiple selections, or simply to navigate through the table content).
Reproduction Steps:
- Launch the code sample below and execute it:
- When you click on different areas on the table you should see the appropriate INDEX numbers, which is the expected and normal behaviour.
BUG Reproduction for currentRow() :
- Now just click on any area on the table and keep the mouse button pressed while changing the selected area on the table
- Down below, you see the currentRow() method returns wrong values (actually it returns the previously selected row's index number)
BUG Reproduction for currentColumn() :
- The currentColumn() method returns wrong values (it returns the previously selected column's index) when you move the mouse cursor at the same row, to the left or to the right columns, while keeping the mouse button pressed.
MORE DETAILS: Here are some problems caused by this BUG:
While the mouse button is pressed to change or select the table cell(s);
- you can never get correct coordinates (row and column) of the current selected cell,
- if the SelectionBehavior is set to rowSelect to navigate through the table contents at each row, you can never get the correct index of current selected row!
EXAMPLE SCENARIOS: Just for example scenarios, Users may need/want to keep mouse button pressed while:
- Navigating through the table contents (the program may use table contents as a navigation menu) or
- selection of multiple rows/cells/columns of the table
- etc.
SAMPLE CODE:
from PySide2 import QtWidgets, QtCore class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") Form.resize(600, 500) Form.setWindowTitle(QtCore.qVersion()) self.label = QtWidgets.QLabel(Form) self.label.setText("[ Row - Col ] (Current INDEX)") self.lineEdit = QtWidgets.QLineEdit(Form) self.tableWidget = QtWidgets.QTableWidget(Form) self.tableWidget.setColumnCount(4) self.tableWidget.setRowCount(10) # Print appropriate INDEX info (Row and Column) in each cell of the table for i in range(10): for j in range(4): self.tableWidget.setItem(i, j, QtWidgets.QTableWidgetItem(f" {i} - {j}")) self.verticalLayout_2 = QtWidgets.QVBoxLayout(Form) self.verticalLayout = QtWidgets.QVBoxLayout() self.verticalLayout.addWidget(self.tableWidget) self.verticalLayout.addWidget(self.label) self.verticalLayout.addWidget(self.lineEdit) self.verticalLayout_2.addLayout(self.verticalLayout) ## Uncomment to see the same BUG when the 'SelectionBehavior' is set to 'rowSelect' # rowSelect = QtWidgets.QAbstractItemView.SelectRows # self.tableWidget.setSelectionBehavior(rowSelect) singleSelect = QtWidgets.QAbstractItemView.SingleSelection self.tableWidget.setSelectionMode(singleSelect) # BUG: Wrong INDEX returns by currentRow() and currentColumn() self.tableWidget.itemSelectionChanged.connect(lambda: self.lineEdit.setText( " " + str(self.tableWidget.currentRow()) + " , " + str(self.tableWidget.currentColumn()))) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Form = QtWidgets.QWidget() ui = Ui_Form() ui.setupUi(Form) Form.show() sys.exit(app.exec_())