1
我有一個QTableView
顯示來自自定義模型的數據。我在每個單元格上都有一個QItemDelegate
版本。視圖的一列有一個由QLineEdit
和QCheckBox
組成的自定義小部件。當我點擊這個列的單元格時,編輯器會顯示出來,它可以工作,但它不適合表格單元格。而且,當我放大一行並單擊單元格時,我可以看到小部件後面單元格的數據。爲QTableView QItemDelegate編輯器上的自定義小部件
有沒有一種方法可以讓我的小部件在視圖上像QItemDelegate
的正常編輯小部件那樣工作?即創建時使用單元的所有垂直空間?
這是我的小部件(簡體):
class MyWidget(QtGui.QWidget):
def __init__(self, parent = None):
super(MyWidget, self).__init__(parent)
self.lineEdit = QtGui.QLineEdit(parent)
self.checkBox = QtGui.QCheckBox(parent)
self.checkBox.setChecked(False)
self.gridLayout = QtGui.QGridLayout(self)
self.gridLayout.setSpacing(3)
self.gridLayout.addWidget(self.lineEdit, 0, 0)
self.gridLayout.addWidget(self.checkBox, 0, 1)
我委託(簡體):
class MyDelegate(QtGui.QItemDelegate):
def __init__(self, parent = None):
super(MyDelegate, self).__init__(parent)
def createEditor(self, parent, option, index):
return MyWidget(parent)
def setModelData(self, editor, model, index):
pass
def setEditorData(self, editor, model, index):
pass
謝謝!它按預期工作。 – user20679