Results 1 to 5 of 5

Thread: QTreeWidget itemAt

  1. #1
    Join Date
    Sep 2008
    Posts
    17
    Thanks
    4
    Thanked 5 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTreeWidget itemAt

    Hi,

    I'm trying to put the contents of a QTreeWidget in a QMultiMap but when I'm checking the result it seems only the first row had been inserted.
    Here's my code:
    Qt Code:
    1. QMultiMap<int, QString> mainInputWidget::returnTravelTableData()
    2. {
    3. QMultiMap<int, QString> rowStrings;
    4. for (int row = 0; row < ui.MItravelTreeWidget->topLevelItemCount(); ++row)
    5. {
    6. for (int column = ui.MItravelTreeWidget->columnCount() - 1; column >= 0; --column)
    7. {
    8. qDebug() << "column" << column;
    9. qDebug() << "row" << row;
    10. rowStrings.insert(row, ui.MItravelTreeWidget->itemAt(row,column)->text(column));
    11. }
    12. }
    13. return rowStrings;
    14. }
    To copy to clipboard, switch view to plain text mode 
    The loops are working right according the qDebugged row and column values, but the problem is with
    Qt Code:
    1. ui.MItravelTreeWidget->itemAt(row, column)
    To copy to clipboard, switch view to plain text mode 
    It keeps pointing to the first row.
    Probably I'm not using this function correctly. What should I do different or is there another solutions that works as well?

    Thanks for answering.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget itemAt

    You are right .. The problem is with
    ui.MItravelTreeWidget->itemAt(row, column)
    itemAt() takes coordinates as arguments , not row/column !!

    second mistake is way of iterating...
    remember QTreeWidget is a TREE. You get top level items from the treewidget. and u can get child items from those.
    So your inner loop should be something like -
    Qt Code:
    1. QTreeWidgetItem *item = ui.MItravelTreeWidget->topLevelItem(row);
    2. for (int column =item->columnCount() - 1; column >= 0; --column)
    3. {
    4. qDebug() << "column" << column;
    5. qDebug() << "row" << row;
    6. rowStrings.insert(row, item->text(column));
    7. }
    To copy to clipboard, switch view to plain text mode 

    Hope this helps

  3. The following user says thank you to aamer4yu for this useful post:

    maartenS (17th September 2008)

  4. #3
    Join Date
    Sep 2008
    Posts
    17
    Thanks
    4
    Thanked 5 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreeWidget itemAt

    Aamer4u thanks!

    I was so focused on this itemAt() function that I completely overlooked the QTreeWidgetItem...
    Thanks for helping me out!
    Now I'm just curious, in what situation do you use the itemAt() function then?

  5. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget itemAt

    hmmm.... how about selection of item ??
    and also if u want to manually drag drop from your tree view... itemAt() will be useful... isnt it ?

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeWidget itemAt

    One common use case for QTreeWidget::itemAt() are item specific context menus.
    J-P Nurmi

Similar Threads

  1. how to sync a QTreeWidget and a QListWidget?
    By zl2k in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2008, 20:55
  2. QTreeWidget nextSibling()
    By user_mail07 in forum Newbie
    Replies: 1
    Last Post: 21st August 2008, 19:44
  3. QTreeWidget click
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 24th October 2007, 16:47
  4. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32
  5. few questions related to QTreeWidget
    By prakash in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2006, 07: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.