[Qt-interest] Tree Item view Highlighter
Andre Somers
andre at familiesomers.nl
Tue Jan 4 10:21:30 CET 2011
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::FixedString);
>
> m_highlightModel->setFilterRegExp(regExp);
>
> }
>
I meant setting the breakpoint in the data() function.
> 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 did not understand that part. A bit more elaboration might be helpful.
Ok, let me try. If you set a new regexp, you expect part of the data to
change (the background color for some of the items in your model). But how
is the view to know that? It needs to be told that the data has changed,
so it can redraw itself. Of course, Qt uses signals and slots for that.
The elegant way to do it is to tell the view exactly which items have
changed by emitting the (proxy-) models changedData signal with the range
of items that have changed. The more course that range is, the more
repainting and requerying of the model the view may have to do. The most
course way is to reset the model completely. This will cause a complete
reset of the view, including the current selection, the current view
position, etc.
You need to signal that change from the slot where you set the new regexp.
That should trigger the view to start requerying the model for the updated
data, and redraw the view appropriately.
André
More information about the Qt-interest-old
mailing list