PDA

View Full Version : Slot "columnsMoved" is not firing?



TorAn
6th November 2014, 15:24
I have a QAbstractTableModel-derived model attached to a QTreeView and I need to be able to track user movement of columns in the view. Luckily QAbstractTableModel has a signal "columnsMoved".
So, I do usual stuff:

ui.lstPairs->setModel(&_model);
bool res1 = connect(&_model, SIGNAL(columnsMoved(const QModelIndex&, int, int, const QModelIndex&, int)),
this, SLOT(columnsMoved(const QModelIndex&, int, int, const QModelIndex&, int)));
if (!res1)
return;
..
and slot implementation:

private slots:
void columnsMoved(const QModelIndex & sourceParent, int sourceStart, int sourceEnd, const QModelIndex & destinationParent, int destinationColumn);
..

void viewPairs::columnsMoved(const QModelIndex & sourceParent, int sourceStart, int sourceEnd, const QModelIndex & destinationParent, int destinationColumn)
{
int i =5; // test
}

When I run it in debug the res1 variable is TRUE, so everything looks normal. Then I start moving the view columns using mouse and my slot is never called. (I place a breakpoint in int i = 5; line)

Question: what can be the problem that causes columnsMoved slot to never be called?
Thanks.

wysota
6th November 2014, 20:08
Moving columns in the view does not cause them to be moved in the model.

TorAn
6th November 2014, 20:18
Oh, I see! I missed that one in the documentation. It states there that "This signal is emitted after columns have been moved within the model.". Then my question is perhaps simpler:

How to detect an event when user moves columns in the view, for example by doing mouse drag of forth column in front of the second and so forth...

Thanks.

ChrisW67
6th November 2014, 21:03
The horizontal QHeaderView emits signals when columns are moved.
QHeaderView::sectionMoved()