Reputation: 176
I am designing a GUI with a QTableView in which one would have to select multiple rows when needed. This means that the first click will select the row and the second click will unselect the row. So there are two specific questions that I have:
Upvotes: 2
Views: 1018
Reputation: 244301
To select rows instead of items you must set them as selection behavior in QAbstractItemView::SelectRows
, and if you want items to be selected without pressing any key you must set the selection mode in QAbstractItemView::MultiSelection
:
import sys
from PyQt5 import QtGui, QtWidgets
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
model = QtGui.QStandardItemModel(10, 5)
w = QtWidgets.QTableView()
w.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
w.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
w.setModel(model)
w.show()
sys.exit(app.exec_())
Upvotes: 2