Results 1 to 6 of 6

Thread: Scroll-to-column in QTreeWidget?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Scroll-to-column in QTreeWidget?

    Hey Santosh,

    Thanks again for taking the time to answer with detailed code.

    I'm afraid I wasn't very clear on my problem, so I created a small test application (Windows, x64) that illustrates well the issue I'm trying to solve:




    Start the application, then press the "Select Random Item" button at the bottom to select a random item in the tree widget. As you will notice, although the tree widget scrolls horizontally to the selected item, the actual text of the item isn't visible as it's too far on the right (due to the indentation). What I'm trying to do is to always make the text of the item visible.

    (Note that, although the tree widget has two columns, only the first one (at index 0) is populated and this is the one I would like to make visible.)

    Franz

  2. #2
    Join Date
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Scroll-to-column in QTreeWidget?

    I solved my problem by simply doing the following:

    Qt Code:
    1. ui->treeWidget->scrollToItem(item);
    2. const QRect r = ui->treeWidget->visualItemRect(item);
    3. ui->treeWidget->horizontalScrollBar()->setValue(r.x());
    To copy to clipboard, switch view to plain text mode 

    Basically, I retrieve the horizontal position of the item within the viewport of the tree widget, then I adjust the horizontal scrollbar such that it aligns with the left of the item.

    Thanks again Santosh for your time.

    Franz

Similar Threads

  1. Replies: 5
    Last Post: 10th October 2011, 13:26
  2. QtreeWidget horizon scroll
    By weixj2003ld in forum Qt Programming
    Replies: 1
    Last Post: 20th April 2009, 10:00
  3. QTreeWidget scroll only one column
    By nina1983 in forum Qt Programming
    Replies: 3
    Last Post: 13th August 2008, 15:07
  4. QTreeWidget won't scroll horizontally
    By JimDaniel in forum Qt Programming
    Replies: 3
    Last Post: 23rd January 2008, 08:53
  5. set Column Width in QTreeWidget?
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2007, 08:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.