PyQT QSqlRelationalDelegate Combobox -
i have form has qtableview qsqlrelationaltablemodel. 2 of columns read only, 1 combobox , 1 spinbox specific range (no negative numbers.)
out of box without qsqlrelationaldelegate, view works combobox automatically on third column , spinbox. in trying put validation in spinbox, found solved readonly problem on first 2 columns. problem how correctly implement combobox on related field foreign key. have been able combobox display can't see how populate choices foreign keys.
how populate combo box?
see code
def setup_rates_view(self): self.rates_model = qsqlrelationaltablemodel(self) self.rates_model.settable("rates_stay") self.rates_model.setrelation(6, qsqlrelation("rates", "rate_code", "rate_description")) self.rates_model.setfilter("id_bookings = '{0}'".format(myapp.res_id)) self.rates_model.setheaderdata(1, qt.horizontal, "date") self.rates_model.setheaderdata(2, qt.horizontal, "basis") self.rates_model.setheaderdata(6, qt.horizontal, "code") self.rates_model.setheaderdata(4, qt.horizontal, "amount") self.rates_model.select() self.rates_view = self.ui.rates self.rates_view.setmodel(self.rates_model) self.rates_view.setitemdelegate(qsqlrelationaldelegate(self.rates_view)) self.rates_view.setcolumnhidden(0, true) self.rates_view.setcolumnhidden(3, true) self.rates_view.setcolumnhidden(5, true) self.rates_view.horizontalheader().movesection(4,6) self.rates_view.resizecolumnstocontents() self.rates_view.setitemdelegate(viewrates(self)) class viewrates(qsqlrelationaldelegate): def __init__(self, parent=none): qitemdelegate.__init__(self) def createeditor(self, parent, option, index): if index.column() == 4: spinbox = qspinbox(parent) spinbox.setrange(0,10000) return spinbox elif index.column() == 6: combo = qcombobox(parent) combo.setmodel() return combo
Comments
Post a Comment