PDA

View Full Version : QTreeview/Model and signals



mgb_qt
31st March 2010, 02:48
I am trying to respond to dblclicks in a Qtreeview derived class with a QAbstractItemModel derived model behind it.

The dblclick event is captured in treeview and gives me an index into the tree.
But all the information to decode what the particular entry is, and how to respond to a dblclick is in treemodel.

Is there a way of accessing the model from the view - there doesn't seem to be a getModel() function.

Or should I re-emit the dblclick signal to a slot in the treemodel, passing on the index, and then let the treemodel send the appropriate signal to my app?

Thanks

foxyproxy
31st March 2010, 07:44
If you have implemented your own model, you can access to it from QTreeView by using QAbstractItemModel * QAbstractItemView::model () const

Lykurg
31st March 2010, 08:14
QAbstractItemModel * QAbstractItemView::model () const
Then you have to cast it eventually. That's no problem, but somewhere you create the model and set it to the view, so just store that pointer to a local member and you can access it everywhere very easy.

mgb_qt
31st March 2010, 15:53
QAbstractItemModel * QAbstractItemView::model () const
Thanks, somehow I missed that in the docs

I used to use the setBlah() / blah() naming for getters and setters but my new company standard is get/set so I was looking for the wrong thing.