QTableView pyqt6中的复选框

发布于 2025-02-08 11:45:48 字数 1753 浏览 2 评论 0原文

我创建了一个使用 QSQLRELATICANTTABLEMODEL 创建了一个QTableView。一切都很好。

我想在列中添加一个复选框。

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)  

“在此处输入图像说明”

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文