Results 1 to 5 of 5

Thread: trying to access treewidget indexFromItem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2012
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question trying to access treewidget indexFromItem

    Hello all,

    I have been trying to make use of the QTreeWidget's indexFromItem to make use to access an actual index on a QStringList (for file writing purposes).

    I can't show code b/c this is an offsite computer, but I need help.

    when I try to do something like this:

    Qt Code:
    1. void on_treeWidget_itemChanged(QTreeItem *item, int column)
    2. {
    3.  
    4. int Index = ui->treeWidget->indexFromItem(item->parent(),0).row();
    5. }
    To copy to clipboard, switch view to plain text mode 

    i get this error message saying indexFromItem is a protected member.

    Ive tried direct input, such as:

    Qt Code:
    1.  
    2. list.removeAt(ui->treeWidget->indexFromItem(item->parent(),0).row());
    To copy to clipboard, switch view to plain text mode 

    or even a failed attempt at getting and setting

    I'm pressed for time, but I was hoping that somebody had the answers to this dilemma.

    Thanks in advance,
    gamenovice

    ps. If I am not being clear, let me know

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: trying to access treewidget indexFromItem

    This is a C++ understanding issue. Protected member functions are only available to the class that contains them or classes that inherit from that class. They behave as private to all others attempting access.

    You are trying to determine which child of the changed item's grandparent is the changed item's parent. Something like:
    Qt Code:
    1. int index = -1; // means not found
    2. QTreeWidgetItem *parent = item->parent();
    3. if (parent) {
    4. QTreeWidgetItem *grandparent = parent->parent();
    5. if (grandparent)
    6. index = grandparent->indexOfChild(parent);
    7. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. add items to treewidget
    By Shien in forum Qt Programming
    Replies: 15
    Last Post: 1st January 2011, 19:40
  2. Replies: 2
    Last Post: 18th May 2010, 22:44
  3. How to add subitem in treewidget
    By phillip_Qt in forum Qt Programming
    Replies: 11
    Last Post: 16th November 2009, 11:22
  4. How to set the sizehint for treeWidget
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2007, 11:35
  5. Painting TreeWidget
    By VireX in forum Qt Programming
    Replies: 9
    Last Post: 9th May 2007, 08:36

Tags for this Thread

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.