I have managed to get around this issue, by implementing the following methods in the custom dialog used by the editor:
import ui_portatilDlg
ui_portatilDlg.Ui_Dialog):
def __init__(self, parent=None):
super(editPortatilDialog, self).__init__(parent)
self.setupUi(self)
def accept(self):
def cancel(self):
from PyQt4.QtGui import QDialog
import ui_portatilDlg
class editPortatilDialog(QDialog,
ui_portatilDlg.Ui_Dialog):
def __init__(self, parent=None):
super(editPortatilDialog, self).__init__(parent)
self.setupUi(self)
def accept(self):
self.setResult(QDialog.Accepted)
QDialog.accept(self)
def cancel(self):
self.setResult(QDialog.Rejected)
QDialog.cancel(self)
To copy to clipboard, switch view to plain text mode
And then modifiying setModelData in the custom delegate:
def setModelData(self, editor, model, index):
if editor.
result() == QDialog.
Accepted: row = index.row()
editor.fotoLabel.pixmap().save(buff, 'PNG')
nombre = editor.nombreLineEdit.text().trimmed()
apellido = editor.apellidoLineEdit.text().trimmed()
model.
setData(model.
index(row, ucols
['NOMBRE']),
QVariant(nombre
)) model.
setData(model.
index(row, ucols
['APELLIDO']),
QVariant(apellido
)) model.
setData(model.
index(row, ucols
['FOTO']),
QVariant(binary
)) model.submitAll()
def setModelData(self, editor, model, index):
if editor.result() == QDialog.Accepted:
row = index.row()
binary = QByteArray()
buff = QBuffer(binary)
editor.fotoLabel.pixmap().save(buff, 'PNG')
nombre = editor.nombreLineEdit.text().trimmed()
apellido = editor.apellidoLineEdit.text().trimmed()
model.setData(model.index(row, ucols['NOMBRE']), QVariant(nombre))
model.setData(model.index(row, ucols['APELLIDO']), QVariant(apellido))
model.setData(model.index(row, ucols['FOTO']), QVariant(binary))
model.submitAll()
To copy to clipboard, switch view to plain text mode
However, I think this is sort of a hack, and that the accept() and cancel() methods should not be overriden, as the correct behavior should be inherited from QDialog.
Bookmarks