Re: qtreeview item's data
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.
Re: qtreeview item's data
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?
Re: qtreeview item's data
Quote:
Originally Posted by
Pawello
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:
Code:
...
qDebug() << Q_FUNC_INFO << model->data(model->index(0, 5));
...
Quote:
Originally Posted by
Pawello
And one more question: how can I make one header column invisible?
See QHeaderView::hideSection.
Re: qtreeview item's data
Quote:
Originally Posted by
spirit
Use
QAbstractItemModel::index to get necessary index. Then you can use it for getting data:
Code:
...
qDebug() << Q_FUNC_INFO << model->data(model->index(0, 5));
...
I dont'understand what do you mean. I suppose that
Code:
data(model->index(0, 5))
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
Thanks, I used QTreeView::setColumnHidden
Re: qtreeview item's data
Did you try this?
Code:
...
QVariant value
= model
->data
(model
->index
(view
->currentIndex
().
row(),
5));
...
Re: qtreeview item's data
It still doesn't work.
I have:
Code:
...
int s=tab->currentIndex().row();
int a=model->data(model->index(s,5)).toInt();
...
Working code, which needs selecting items in 5th column :
Code:
...
int a=tab->currentIndex().data().toInt();
...
Re: qtreeview item's data
That's because the current index == (0, 0) or invalid.
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.
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)).
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.
Re: qtreeview item's data
Try to debug your app. Or provide complete compilable code.