How To Signal QTreeView To ScrollTo Selected Item In Model?
-
I have a graphics view and QTreeView which view the same model. When I select an item in the graphic's view I want to send a signal to the QTreeView to select the corresponding row of the graphic's item and then scrollTo() it (and expand actually). The graphics scene and QTreeView share the same QItemSelectionModel. QTreeView has a scrollToTop() and scrollToBottom() slots but no slot that I can see for arbitrary scrolling.
Am I wrong in thinking I need to derive my own tree view from QTreeView and add a slot so I can connect the QItemSelectionModel's signal to my own slot to autoscroll? That just seems wrong.
I see that Qt's Creator IDE (which is great by the way) has this feature. When you click a file name in the "Open Documents" the file tree in the "Projects" window autoscroll and expand.
-
Hi,
you are right, there is no slot for that functionality, but a function: "QAbstractItemView::scrollTo":http://doc.qt.nokia.com/4.7/qabstractitemview.html#scrollTo so you can just create a slot in your main window and call scrollTo from there, no need to derive the view if you need this only in 1 place.
-
Doing this in an animated way was discussed on this forum recently. Please read back a bit.
-
Thanks. I see. In general I have been a bit concerned about best practices when it comes to creating signals and slots and making connections. I picture it like wiring... and I'm afraid I might create a nightmare of tangled wires between boxes all over the place. I guess the key is like you said, "if you need this only in 1 place"
-
Thanks, Andre. I found the discussion: http://developer.qt.nokia.com/forums/viewthread/5944/
I'll read it.