Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyQt4 - How to select table rows and disable editing cells

Tags:

python

pyqt4

I create a QTableWidget with:

self.table = QtGui.QTableWidget()
self.table.setObjectName('table')
self.table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
verticalLayout.addWidget(self.table)

with this selection it is possible to select rows but I don't want that the user can edit any cells of this table. I know that you can enable each cell while filling the table. But is there a possibility to set the cells of the whole table kind of inactive (after the filling of the table) while the selection of the rows is still possible?

TIA Martin

like image 755
Martin Avatar asked Jun 14 '13 08:06

Martin


2 Answers

use

self.table.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)

(here you can find other triggers, just in case you need them)

like image 67
Nerkyator Avatar answered Oct 08 '22 15:10

Nerkyator


You can disable editing by setting the flags ItemIsSelectable and ItemIsEnabled for each item in your table:

table = QTableWidget(10,10)

for i in range(10):
    for j in range(10):
        item = QTableWidgetItem(str(i*j))
        item.setFlags( Qt.ItemIsSelectable |  Qt.ItemIsEnabled )
        table.setItem(i, j, item)
like image 25
Jaime Ivan Cervantes Avatar answered Oct 08 '22 17:10

Jaime Ivan Cervantes