PDA

View Full Version : How to catch QTreeView column moved by user?



liversedge
26th July 2010, 11:23
Hi,

I have searched and searched but can't find an answer to this.

I am using a plain QTreeView ontop of a QSqlTableModel to display the contents of an SQLlite table. It's working just fine.

I want to keep a track of the headings in the TableView so I can restore their state when the program is relaunched, and have happily hidden/shown/moved columns programmatically.

However, I need to be able to trap when a user drags a column heading from one place to another (which is a nice feature of QTreeView). But there appears to be no signals or events that I can trap to spot this.

I tried subclassing QTreeView and implementing all the protected slots like columnMoved(), removeRows() et al but that didn't do anything (although the removeRows slot did get called from time to time). I tried installing an eventFilter on the QTableView but got very few events that could help (in/out/tooltip request).

So, how can I trap when a user drags the column heading and moves it in a QTreeView?

Many thanks in advance,
Mark

Lykurg
26th July 2010, 21:07
You have to combine things: QTreeView::header() -> QHeaderView::sectionMoved().