QTableView pyqt6中的复选框
我创建了一个使用 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论