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 qtreeview item's data

    Hi,
    I have a problem with QTreeView. I want to read QString from selected cell, or (starting) index of this cell but I dont know how to do it. I've tried to use currentIndex(), but it shows position in current View- no matter which item is on first place in window after sorting or filtering it's index is always 0,0.

  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

    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Pawello (23rd August 2012)

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

    Default Re: qtreeview item's data

    this could help, but I dont know how can I use it to extract int value from e.g. 5. cell of selected row.

  5. #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

    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: qtreeview item's data

    I've found this, but how to get data from e.g 5th. cell of the row.
    E.g. No matter if I choose item at x,0 or x,1 I want to read data from x,5



    And one more question: how can I make one header column invisible?

  7. #6
    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

    Quote Originally Posted by Pawello View Post
    I've found this, but how to get data from e.g 5th. cell of the row.
    E.g. No matter if I choose item at x,0 or x,1 I want to read data from x,5
    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 

    Quote Originally Posted by Pawello View Post
    And one more question: how can I make one header column invisible?
    See QHeaderView::hideSection.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  8. #7
    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

  9. #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

    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].

  10. #9
    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 

  11. #10
    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].

  12. #11
    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.

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.