[PyQt4] QTableWidget Readonly?
-
Ok, sorry for that stupid question, but I'm new to pyQt and object orientated programming.
QTableWidgetItem is only a cell of the QTableWidget? is that correct?I create an instance of QTableWidget as self.addip_tw and added the self.addip_tw to a QGridLayout.
So I have to do the setFlags for every cell in my Table? -
@Daniel26 said in [PyQt4] QTableWidget Readonly?:
QTableWidgetItem is only a cell of the QTableWidget? is that correct?
Not exactly, it's an object that will be stored in the model coming with QTableWidget and provide all the necessary data to be rendered by a cell of the table.
A QTableWidget is a QTableView + a model all packed in one.
You should check the Model/View Programming chapter in Qt's documentation for a good overview of how it is working.
-
@Daniel26
You can indeed do it as @Denni-0 has said. To my mind, it doesn't really make the cells read-only, but it does stop the user doing anything to edit :) And it's only one line!For making the items not-editable, you could look at the code in https://stackoverflow.com/questions/7727863/how-to-make-a-cell-in-a-qtablewidget-read-only/ which is the accepted solution. Other answers there also show @Denni-0 's approach.