problem to edit cell in qtablewidget

Luca Bertolotti luca72.bertolotti at gmail.com
Tue Sep 10 09:30:13 BST 2024


Hello
i have add this in my app
class Form(QWidget, Ui_Form):
    """
    Class documentation goes here.
    """

    def __init__(self, parent=None):
        """
        Constructor

        @param parent reference to the parent widget (defaults to None)
        @type QWidget (optional)
        """
        super().__init__(parent)
        self.setupUi(self)

        self.tableWidget.keyPressEvent = self.copy_paste

then I add a def
     def copy_paste(self,event):
            if event.key() == Qt.Key.Key_C and (event.modifiers() &
                           Qt.KeyboardModifier.ControlModifier):
            self.copied_cells = sorted(self.tableWidget.selectedIndexes())
            print(self.copied_cells)
        if event.key() == Qt.Key.Key_V and (event.modifiers() &
Qt.KeyboardModifier.ControlModifier):
            r = self.tableWidget.currentRow() - self.copied_cells[0].row()
            c = self.tableWidget.currentColumn() -
self.copied_cells[0].column()
            for cell in self.copied_cells:
                self.tableWidget.setItem(cell.row() + r, cell.column() + c,
QTableWidgetItem(cell.data()))


The copy_paste work but I can't edit the cells what is wrong??
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20240910/e2dd12d0/attachment.htm>


More information about the PyQt mailing list