PDA

View Full Version : Get indices of rows where the signal dataChanged() was emitted



yannwilfried
6th August 2013, 09:04
Hello all,

I have a model displaying data in a tree view. I implemented a proxy model to show some categories of the tree view in a table view. On my table view, I have on each column different types of items (QComboBox, 3 x QDoubleSpinBox and a QCheckBox). I'm plotting various curves depending on the data in my Table. I'm plotting data stored in the rows and to be able to update my plot, I will like to react to changes in the combo box, the spin boxes and the check box.

Is there a way to catch the row where a signal whas a emitted or do I need to write a slot that react to the signals
currentIndexChanged (http://qt-project.org/doc/qt-4.8/qcombobox.html#currentIndexChanged), valueChanged (http://qt-project.org/doc/qt-4.8/qdoublespinbox.html#valueChanged-2) and stateChanged (http://qt-project.org/doc/qt-4.8/qcheckbox.html#stateChanged).

Thanks for your hints,
Yann

wysota
6th August 2013, 09:14
How did you put those widgets there?

yannwilfried
6th August 2013, 09:30
I'm using a custom delegate that inherits QStyledItemDelegate.

Edit: Your question let me think a bit. Actually I'm using the same delegate between the tree view and the table view since I'm sharing the same model between both views. Wouldn't it be easier to implement a second delegate for the table view and emit myself the signal commitData (http://qt-project.org/doc/qt-4.8/qabstractitemdelegate.html#commitData)?

wysota
6th August 2013, 10:45
Using QStyledItemDelegate doesn't explain how you put widgets inside item cells. Did you implement all functionality of the widgets yourself or have you used real widgets? If the former then there are no signals there as there are no widgets to emit them. If the latter then I repeat my question -- how did you put those widgets there.

yannwilfried
6th August 2013, 12:18
If by real widgets you mean the Qt widgets, I'm just reimplementing the createEditor (http://qt-project.org/doc/qt-4.8/qstyleditemdelegate.html#createEditor) method and setting my widget at the specified index.

wysota
6th August 2013, 12:36
You mean you createEditor returns a QWidget that has e.g. three double spin boxes inside, etc., yes?

If so then your editor widget (the "top level" widget you return) should expose one or more properties that will be used in setModelData() and setEditorData() to sync the editor and the model. Qt will be able to handle standard property types by itself (assuming the property is marked as a USER property), for non-standard you have to reimplement setModelData and setEditorData and do the syncing yourself.

yannwilfried
8th August 2013, 09:19
I already reimplemented setModelData and setEditorData. I made a basic mistake by handling of the dataChanged() signal that I was invoking like
dataChanged(QModelIndex &, QModelIndex &) instead of
dataChanged(const QModelIndex &, const QModelIndex &).