Hello forum,

I am trying to highlight a particular tree-item based on the string entered by the user in the line edit and i am doing the following:


1. I subclass the QSortFilterProxyModel and over-ride the data() function as follows:

1.1. map the model index to the source.

1.2. Check if the mapped model index is valid or not.

1.3. And change the color of the background using the background role.

2. In the widget i have the line edit and the tree view which will be interacting with each other based on the user input.

3. In the widget's constructor i instantiate the object of the subclass that i have creaed in step 1.

4. Set its source model.

5. Set view to both the model and proxy model.

6. Made a signal & slot connection - whenever the text inside the textedit is changed, the custom slot is called to do the highlighting s follows:


6.1. Create a regular expression object , which takes the following parameter:

6.1.1. The text from the line edit - 1st parameter.
6.1.2. Flag - Qt::CaseInsensitive.
6.1.3. Flag - Qt::FixedString.


6.2. Declare two model indexes and initializing as follows(THIS IS WHERE I AM MAKING THE MISTAKE I GUESS):

Qt Code:
  1. const QModelIndex topLeft = m_highlightModel->index(0,0,QModelIndex());
  2. const QModelIndex bottomRight = m_highlightModel->index(0,m_highlightModel->columnCount()-1,topLeft);
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. emit proxyModelHighlightChanged(topLeft,bottomRight);
  13.  
  14.  
  15.  
  16. //emit m_highlightModel->dataChanged(topLeft,bottomRight);
  17.  
  18.  
  19. connect(this,SIGNAL(proxyModelHighlightChanged(QModelIndex,QModelIndex)),m_highlightModel,SIGNAL(dataChanged(QModelIndex,QModelIndex)));
To copy to clipboard, switch view to plain text mode 

Now i am not getting the effect i am looking for. I am looking for the following:



1. Whenever the user enters any text in the line edit, the text will be matched against all the tree item and highlighted.


2. Some of the item may be hidden as the parent item is not expanded. In that case the parent will be expanded and the child will be
highlighted.


3. If the entered string does not match , nothing will happen.



But i am getting the following:


1. All the items are highlighted, when the application is loaded.

2. The item inside the tree is filtered when the entered string matches any item, thus reducing the number of items in the tree . I do not want to alter anything inside the

tree view. I just want to highlight the tree item by changing the background color.


3. I can match only the parent item, but cannot go down to the child and sub-childs item and high-light it.


I hope that i am elaborated enough. If it is not clear enough for any one of you, please do not hesitate to comment. It has been
quite a while i am stuck with this issue. Any tips will be helping a lot.



NOTE: Couple of days ago my email account has been cracked and it might had spammed the forum. If there were anything totally
non-related to Qt, it was not me. The account setting is restored now. If those materials disturbed anyone i deeply apologise
for it.


Thanks
Sajjad