0

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

musicamante
  • 41,230
  • 6
  • 33
  • 58
  • 1
    Note that Qt models and views already support that, using the `Qt.CheckStateRole`. That said, please provide a [mre]. – musicamante Jun 17 '22 at 23:44
  • I've used [this](https://github.com/Numerlor/Auto_Neutron/blob/381096c9ffcc52a3f4dc48b83345fc9bd900d083/auto_neutron/windows/gui/delegates.py#L47-L139) delegate to get a standalone checkbox for a table widget, I believe it'd also be applicable here. Your methods that only call the super method should also be unnecessary to define – Numerlor Jun 18 '22 at 00:11

0 Answers0