Checkbox in QTableView PyQt6

420 Views Asked by At

I have created a QtableView with QSqlRelationalTableModel. All works fine.

I would like add a checkbox to column.

class myQSqlRelationalDelegate(QSqlRelationalDelegate):
 
    def __init__(self, parent=None):
        QStyledItemDelegate.__init__(self)

    #Overraiding the metodo paint
    def paint(self, painter, option, index):

       #default 
       return super().paint(painter, option,index)    


    #Overraiding the metodo createEditor
    def createEditor(self, parent, option, index):
 
        if index.column() == 1:
                widget = QDateEdit(parent)
                widget.setStyleSheet(style)
                widget.setCalendarPopup(True)
                widget.date()
                return widget

        if index.column() == 6:
    
            checkbox = QCheckBox(parent)
            checkbox.setCheckable
            return checkbox
        
        else:
            #default
            return super().createEditor(parent, option, index)        

    #Overraiding the metodo setEditorData
    def setEditorData(self,editor, index):
        
        #default
        return super().setEditorData(editor, index)

    #Overraiding the metodo setModelData
    def setModelData(self, editor, model, index):

        #default
        return super().setModelData(editor, model, index)      

    #Overraiding the metodo sizeHint
    def sizeHint(self, option, index):

        #default
        return super().sizeHint(option, index)

     #Overraiding the metodo updateEditorGeometry
    def updateEditorGeometry(self,editor, option, index):

        #default  
        return super().updateEditorGeometry(editor, option, index)  

enter image description here

0

There are 0 best solutions below