def __init__(self, model, attr): self.widget = QtGui.QLineEdit() self.model = model self.attr = attr self.value = getattr(self.model, self.attr) self.widget.setValidator(QtGui.QIntValidator())