[Qt-interest] Tree Item view Highlighter

Scott Aron Bloom Scott.Bloom at onshorecs.com
Tue Jan 4 18:53:37 CET 2011


On Tue, Jan 4, 2011 at 10:21 AM, Andre Somers <andre at familiesomers.nl>
wrote:

Op Di, 4 januari, 2011 9:21 am, schreef Sajjad:


>>  Is there anything missing up there? I removed the other function
that i
>> over-rid mentioned in the previous post.
>>
>>  I am still not getting any effect. The textchanged() signal is
>> connected
>> to  the slot as before.
>>
>> Ah, of course... Sorry about that.
>>
>> First of all: are you getting an effect if you set a fixed regexp to
>> begin
>> with? If not, then something is wrong in the code above. Set a
>> breakpoint
>> where you return the color and see if you ever arrive there at all...
>>
>
> I set the breakpoint at the slot
>
>   void H3DNodeListWidget::highlightRegExpChanged()
>
> {
>
>     QRegExp
>
regExp(m_nodeHighlightingEditor->text(),Qt::CaseInsensitive,QRegExp::Fix
edString);
>
>      m_highlightModel->setFilterRegExp(regExp);
>
> }
>

I meant setting the breakpoint in the data() function.

 

The breakpoint  has been set there as well.

	
	> And i did not reach  the data() function while stepping into
the code.

	I can imagine it did not.

	
	>> However, I think the problem is, that you need to notify your
view that
	>> the
	>> data has changed if your regexp changes. For testing, just
emit reset(),
	>> but
	>> in your real implementation, you should probably be a bit
nicer and emit
	>> dataChanged() with the right modelindexes.
	>>

i believ ethat the dataChanged() signal two model indexes as input
parameter. I need to highlight only one tree item that maches the
expression in the line edit. In that case how should i set the value for
the signal that takes 2 input parameters. Should it be the same source
index specified twice? I tried something as follows:

 

////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////

 

QVariant H3DHighlighterProxyModel::data(const QModelIndex &index, int
role) const
{
    //get  the handle to  the underlyiing data
    QModelIndex  sourceIndex = mapToSource(index);
    if(!sourceIndex.isValid())
    {
        return QVariant();
    }
    if(role == Qt::BackgroundRole)
    {
 
if(sourceModel()->data(sourceIndex).toString().contains(filterRegExp()))
        {
 
            //the following statement gives error because the virtual
function itself  
 
            //declared const 
            emit dataChanged(sourceIndex,sourceIndex);
            return Qt::cyan;
        }
        else
        {
            //return the default background color
            //whatever may it be
            return QVariant();
        }
    }
    else
    {
        return sourceIndex.data(role);
    }
}

 

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////

 

 

And then if i have to set the connection as follows, i believe that it
will not be valid:

 

connect(m_proxyMode,dataChanged(QModelIndex,QModelIndex),m_treeView,SLOT
(update(QModelIndex))));

 

As you can see that the parameters are not matching. 

 

>From all  the discussions you can imagine that i am having trouble to
grasp the basic idea of model.view programming.

Could you provide some references where these issues are well discussed?

 

 

Regards

Sajjad

	-----------------------

 

 

Yes, read the Qt documentation on model view programming...  and the
signal/slot programming...

 

The dataChanged signal, allows you to send out a "square" of topLeft to
bottomRight inclusive...  If topLeft == bottomRight, then only that cell
is updated.

 

As to your update connection, you shouldn't have to, all views are
automatically connected to the dataChanged signal

 

Scott

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110104/eb00c748/attachment.html 


More information about the Qt-interest-old mailing list