Results 1 to 14 of 14

Thread: qtreeview item's data

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2012
    Posts
    25
    Thanks
    10

    Default Re: qtreeview item's data

    Quote Originally Posted by spirit View Post
    Use QAbstractItemModel::index to get necessary index. Then you can use it for getting data:
    Qt Code:
    1. ...
    2. qDebug() << Q_FUNC_INFO << model->data(model->index(0, 5));
    3. ...
    To copy to clipboard, switch view to plain text mode 
    I dont'understand what do you mean. I suppose that
    Qt Code:
    1. data(model->index(0, 5))
    To copy to clipboard, switch view to plain text mode 
    will always give me data from index 0,5
    My problem is that I want to use current index' row and set index column as 5- only column must be constant, row depends on the chosen cell.



    Quote Originally Posted by spirit View Post
    Thanks, I used QTreeView::setColumnHidden

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: qtreeview item's data

    Did you try this?
    Qt Code:
    1. ...
    2. QVariant value = model->data(model->index(view->currentIndex().row(), 5));
    3. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jul 2012
    Posts
    25
    Thanks
    10

    Default Re: qtreeview item's data

    It still doesn't work.
    I have:
    Qt Code:
    1. ...
    2. int s=tab->currentIndex().row();
    3. int a=model->data(model->index(s,5)).toInt();
    4. ...
    To copy to clipboard, switch view to plain text mode 

    Working code, which needs selecting items in 5th column :
    Qt Code:
    1. ...
    2. int a=tab->currentIndex().data().toInt();
    3. ...
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: qtreeview item's data

    That's because the current index == (0, 0) or invalid.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Jul 2012
    Posts
    25
    Thanks
    10

    Default Re: qtreeview item's data

    So what should I do? I don't see any difference between my code and code posted by you previously, but it doesn't work properly.
    Last edited by Pawello; 23rd August 2012 at 14:42.

  6. #6
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qtreeview item's data

    What does "it doesn't work" mean? At this point no one can do anything for you beyond playing guessing games.

    By the way, row and column numbering is 0-based, so if you are interested in the 5th column you will should use model->data(model->index(view->currentIndex().row(),4)).

  7. #7
    Join Date
    Jul 2012
    Posts
    25
    Thanks
    10

    Default Re: qtreeview item's data

    I know about starting numeration from 0.
    When I'm using second code program works well and read pointed cell's info, no matter if view was sorted, filtered... but when I use first code it shows number depending on position of item in current view, not information from 5th column. It use current index of item instead of value from 5th column.

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: qtreeview item's data

    Try to debug your app. Or provide complete compilable code.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. QTreeview item readonly
    By ken123 in forum Qt Programming
    Replies: 2
    Last Post: 31st October 2011, 17:22
  2. QTreeView Checkable Item
    By fruzzo in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2011, 10:41
  3. Disable QTreeView item
    By tmmak in forum Qt Programming
    Replies: 2
    Last Post: 1st February 2011, 08:33
  4. QTreeView item color
    By tmmak in forum Qt Programming
    Replies: 1
    Last Post: 11th January 2011, 06:08
  5. Buttons on item in QTreeView?
    By joeld42 in forum Qt Programming
    Replies: 1
    Last Post: 9th October 2010, 01:27

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.