[Qt-interest] qtreeview - hot do I get current item?

Andre Somers andre at familiesomers.nl
Mon Feb 15 10:53:58 CET 2010


Andre Somers wrote:
> Iuri Fiedoruk wrote:
>   
>> Now what I want, is that when the user clicks or use keyboard to 
>> change the selected item in the tree, I get information about it. 
>> I tryied the click, like this:
>>
>> (...)
>>     
>
>   
>> But item is always empty.
>> Can you please help me to find a way to just get the text/data from 
>> the current selected item in the tree when it is changed?
>>     
> Check out the signals QAbstractItemView provides. Your tree view derives 
> from it, so it will also emit these signals. Connect to the signal that 
> suits your needs. If none of these do the trick, every view also has a 
> selection model, which you can get a pointer to. This selection model 
> also has some signals that may interest you.
>
> André
>   
By the way: if you want the current item at any other time, you can 
access it through the views currentIndex() method, like you do. To get 
to the item, you should use the model however, using the itemFromIndex 
method. You already have the index, so use it!

Most information can also be accessed directly from that index. 
QModelIndex::data can tell you the text directly without going through 
QStandardModel (-Item).

André




More information about the Qt-interest-old mailing list