Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How To Signal QTreeView To ScrollTo Selected Item In Model?
Qt 6.11 is out! See what's new in the release blog

How To Signal QTreeView To ScrollTo Selected Item In Model?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 9.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    texas
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      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.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Doing this in an animated way was discussed on this forum recently. Please read back a bit.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          texas
          wrote on last edited by
          #4

          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"

          1 Reply Last reply
          0
          • T Offline
            T Offline
            texas
            wrote on last edited by
            #5

            Thanks, Andre. I found the discussion: http://developer.qt.nokia.com/forums/viewthread/5944/
            I'll read it.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved