Results 1 to 4 of 4

Thread: [QT4] Selected row in a QTreeWidget

  1. #1
    Join Date
    Jan 2006
    Location
    Innsbruck, Austria
    Posts
    62
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default [QT4] Selected row in a QTreeWidget

    I'm using a QTreeWidget to display a list with two columns, so I only insert toplevel items on it. I only allow the user to select one row. Is there a way to know which row is actually selected? I mean the row number, not the QTreeWidgetItem. Thx.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [QT4] Selected row in a QTreeWidget

    Maybe something like this?
    Qt Code:
    1. int MyTree::currentRow(){
    2. QTreeWidgetItem *item = currentItem();
    3. int ind = 0;
    4. while((QTreeWidgetItem *wi = child(ind))!=0){
    5. if(item==wi) return ind;
    6. ind++;
    7. }
    8. return -1;
    9. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    50
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [QT4] Selected row in a QTreeWidget

    I think you need to use this method:
    Qt Code:
    1. int pos = treeWidget->indexOfTopLevelItem ( treeWidget->currentItem())
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [QT4] Selected row in a QTreeWidget

    May be it can help a bit.

    _pKeywordSummeryTree->selectionModel()->select(_pKeywordSummeryTree->model()->index(_pKeywordSummeryTree ->indexOfTopLevelItem(item),0),QItemSelectionModel: :Select);

Similar Threads

  1. QTreeWidget selection
    By adhit in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2008, 10:08
  2. Showing a QtreeWidget branch as selected
    By MrGarbage in forum Qt Programming
    Replies: 2
    Last Post: 25th January 2008, 09:56
  3. Having trouble clearing a QTreeWidget.
    By Nyphel in forum Qt Programming
    Replies: 28
    Last Post: 10th October 2007, 16:33
  4. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 23:32

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.