Results 1 to 6 of 6

Thread: Scroll-to-column in QTreeWidget?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Scroll-to-column in QTreeWidget?

    Try this, I have checked it works just fine.
    Qt Code:
    1. QModelIndex computeModelIndex(QTreeWidgetItem * item, int column = 0)
    2. {
    3. QModelIndex index;
    4.  
    5. if(item == 0)
    6. return index;
    7.  
    8. QTreeWidget * treeWidget = item->treeWidget();
    9.  
    10. if(treeWidget == 0)
    11. return index;
    12.  
    13. QTreeWidgetItem * parent = item->parent();
    14.  
    15. if(parent)
    16. return computeModelIndex(parent, 0).child(parent->indexOfChild(item), column);
    17.  
    18. return treeWidget->model()->index(treeWidget->indexOfTopLevelItem(item), 0);
    19. }
    20.  
    21. //elsewhere
    22. QModelIndex index = computeModelIndex(item, 9);
    23. if(index.isValid())
    24. mTreeWidget->scrollTo(index);
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  2. The following user says thank you to Santosh Reddy for this useful post:

    dictoon (23rd May 2013)

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.