동일한 열의 모든 선택된 값을 동시에 편집하는 문제를 좀 더 간단하게 해결할 수도 있습니다. QTableView :: edit()를 재정의하는 대신 사용자가 편집을 제출 한 후에 호출되는 QTableView :: commitData (편집기)를 재정의하는 것이 더 쉽습니다.
간단히 말해서 : 사용자가 편집을 전송하면 선택한 다른 모든 행을 반복하고 편집 된 셀과 같은 열의 셀에 정확히 동일한 값 변경을 적용합니다.
여기 파이썬 예제, C++로 번역 (사방에 세미콜론을 추가, this
와 self
교체) 쉬워야한다 :
는
class ImageTableView(QtGui.QTableView):
def commitData(self, editor):
# call parent commitData first
super(ImageTableView, self).commitData(editor)
# self.currentIndex() is the QModelIndex of the cell just edited
theModel = self.currentIndex().model()
# get the value that the user just submitted
value = theModel.data(self.currentIndex(), QtCore.Qt.EditRole)
curRow, curCol = self.currentIndex().row(), self.currentIndex().column()
# selection is a list of QItemSelectionRange instances
for isr in self.selectionModel().selection():
rows = range(isr.top(), isr.bottom()+1)
for row in rows:
if row != curRow:
# row,curCol is also in the selection. make an index:
idx = theModel.index(row, curCol)
# so we can apply the same value change
theModel.setData(idx, value, QtCore.Qt.EditRole)
QTableModel' '같은 것은 없습니다. QStandardItemModel을 사용하고 있습니까? – Phlucious
어쨌든 공용 인터페이스가 없습니다. – Phlucious
죄송합니다. public QAbstractTableModel 및 flags(), data(), setData(), headerData(), setHeaderData(), columnCount() 및 rowCount()를 덮어 쓰는 클래스 MyModel을 사용하고 있습니다. 그리고 다른 한편으로는 MyTableView : public QTableView를 사용하고 있습니다 ... – Donny