PDA

View Full Version : qtableview signal to model for internal drag and drop?



RolandHughes
15th November 2014, 23:20
What signal should the model receive from a QTableView when an internal drag and drop has completed? I'm befuddled. I re-implemented dropMimeData() and set a break in it, but that never gets called and I wouldn't expect it to for an internal move. There has to be _something_ which gets sent back so the model can adjust what it sends for header data...or is this magic which happens only in the view and it does not communicate to the model? Ideally I need to know what the new column order is so I can save that for future use.

A secondary, and not as important question: How does one actually block certain columns from being moved, especially having other internal columns moved around them? The result of flags() seems to be completely ignored when it comes to internal moves. Perhaps that is the nature of the beast?

Thanks,
Roland

wysota
16th November 2014, 07:33
What signal should the model receive from a QTableView when an internal drag and drop has completed?
Internal drag and drop is not done via signals. For a general drag and drop you should reimplement mimeTypes(), mimeData() and dropMimeData(). For internal drag and drop it could be that the view tries to simply call moveRows() on the model.


I re-implemented dropMimeData() and set a break in it, but that never gets called and I wouldn't expect it to for an internal move. There has to be _something_ which gets sent back so the model can adjust what it sends for header data...or is this magic which happens only in the view and it does not communicate to the model? Ideally I need to know what the new column order is so I can save that for future use.
Aren't you mixing two things? Internal drag and drop is not about repositioning columns in the view, it is about moving single items within the model. Repositioning columns in the view does not affect the model in any way.

RolandHughes
16th November 2014, 10:34
Aren't you mixing two things? Internal drag and drop is not about repositioning columns in the view, it is about moving single items within the model. Repositioning columns in the view does not affect the model in any way.


That is _so_ not cool. If the view never communicates the repositioning of columns there is no way to save the user selected configuration across boots or navigations. As to "mixing", I don't know. I had to enable internal drag and drop on the header in order to move columns.


Internal drag and drop is not done via signals. For a general drag and drop you should reimplement mimeTypes(), mimeData() and dropMimeData(). For internal drag and drop it could be that the view tries to simply call moveRows() on the model.

Thanks. I will look for moveColumns() and see if it actually gets called. There has to be _some_ way of preserving the user selected column order across instantiations of the tableview.

anda_skoa
16th November 2014, 12:14
That is _so_ not cool. If the view never communicates the repositioning of columns there is no way to save the user selected configuration across boots or navigations.

Why would that not be possible?
All the necessary information is available at the source (for moved columns the vertical header view).



As to "mixing", I don't know.

While the user interaction is quite similar, the result is not.
A drag&drop of items changes the structure of the model (shared between all views on that model), a drag&drop of header sections changes the way this particular view displays the data (specific to that view).



I had to enable internal drag and drop on the header in order to move columns.

You mean QHeaderView::setSectionsMovable()?




Thanks. I will look for moveColumns() and see if it actually gets called. There has to be _some_ way of preserving the user selected column order across instantiations of the tableview.
Also have a look at http://qt-project.org/doc/qt-5/qheaderview.html#sectionMoved

Cheers,
_