QAbstractItemModel / QStyledItemDelegate howto update data on value changed?
Hi there,
I have QAbstractItemModel and displaying its data in a QTableView.
A derived QStyledItemDelegate class creates an QSpinBox to edit values in
column 1.
A QSpinbox on some other place on the widget where the QTableView is nested,
shows the same data eg. (2/1), the QSpinbox is connected through QWidgetMapper.
Actually it works fine: I can change both value and they update each other if
I change the focus.
But thats the point! The changed values have to immediately update the model
data. How can I force that the valueChange() signal update the model data.
Therefore if I insert a number directly in the spinbox and press enter,
the number jumps back to the old value. Only the up/down button works to edit
the value.
Thanks for help
Re: QAbstractItemModel / QStyledItemDelegate howto update data on value changed?
You should be connecting the outer / other QSpinBox to QAbstractItemModel, and not to the QTableView's or QStyledItemDelegate's QSpinBox, are you doing it this way?
Re: QAbstractItemModel / QStyledItemDelegate howto update data on value changed?
Yes:
Code:
otpTableView.setModel(otpmodel)
otpTableView.setItemDelegate( OtpDelegate_C(this) )
mapper_r1.setModel(otpmodel)
mapper_r1.addMapping(label_row1, 0, "text")
mapper_r1.addMapping(spinbox_row1, 1)
mapper_r1.setCurrentIndex(1)
Anyway the problem is that the data from the editor will be send to the model only after the editor lost the focus. I think that is normal behavior for models indeed.
But if you connect eg. a slider with spinbox, you can see intstandly the changing values. That`s what I have to achieve.
Thanks
Re: QAbstractItemModel / QStyledItemDelegate howto update data on value changed?
In that case use QSpinBox::valueChanged() signal
Re: QAbstractItemModel / QStyledItemDelegate howto update data on value changed?
Ups, some post get lost somewhere ???
Thanks Santosh, but I dosn`t connect anything it goes autmaticaly by
Code:
mapper_r1.addMapping
Maybe I have to derive QTableView and QDataWidgetMapper to force some signals
Re: QAbstractItemModel / QStyledItemDelegate howto update data on value changed?
I improved the code to
Code:
mapper_r2.setModel(otpmodel)
mapper_r2.addMapping(label_row2, 0, "text")
mapper_r2.addMapping(spinbox_row2, 1)
mapper_r2.setCurrentIndex(1)
connect(
spinbox_row2, SIGNAL(valueChanged(), otpmodel, SLOT(dataChanged()))
)
But as expected, the value isn`t set to the model already , so an dataChanged() isn`t enough :(
Re: QAbstractItemModel / QStyledItemDelegate howto update data on value changed?
There is no such SLOT in QAbstractItemModel