Subject: Re: QTreeView setFirstColumnSpanned?

Tomaz Canabrava tcanabrava at kde.org
Sun Jun 9 13:43:20 PDT 2013


On Sun, Jun 9, 2013 at 5:24 PM, Linus Torvalds
<torvalds at linux-foundation.org> wrote:
> On Sun, Jun 9, 2013 at 11:03 AM, Amit Chaudhuri
> <amit.k.chaudhuri at gmail.com> wrote:
>>
>> QTreeView has a protected virtual method for drawing a row.  I've not had
>> time to look at the code for that in any detail, but it sounds like an
>> invitation to sub-class and get any row specific behaviour we wish to have.
>>
>> So we might consider something like this:
>>
>> - sub-class QTreeView
>
> We already do this (DiveListView).
>
>> - re-implement drawRow
>
> Ok, I did that, easy enough.
>
>> - in our drawRow, test ( isTrip() )
>
> Done.
>
>> - compose the custom string we want to display from trip data "fields"
>
> Done (ok, for now I just take the name).
>
>> - display trip in our custom manner
>
> .. but this is a *bitch*.
>
> Why? The drawRow() function seems to be complex as hell. It has to
> know all the insane private details of the QTreeView. It needs to do
> all the background color selection (possibly alternating), the "is
> this row selected" stuff, yadda yadda. Looking at the sources of the
> *normal* drawRow(), this is very painful.
>
> But maybe there is some shortcut that I don't know about.
>
>> - else do the usual - 'cos it's not a trip
>
> Well, that's the trivial case.
>
> Anyway, the appended patch does everything *except* for the actual
> drawing of the string. Which looks insanely complex to somebody that
> doesn't know Qt. Can anybody fill in the missing blanks (literally:
> there is a comment like
>
>      /* Draw 'trip->name' here ! */
>
> but since it doesn't do it, the trip rows end up being blank).
>
>                    Linus

Nonono - don't reimplement drawRow unless you *really* have a reason
too ( like, almost never ), or wanted to create your widget from
scratch.

>From what I understood, Linus wants the Trips to have 2 or 3 Columns,
and Dives to have more, right?
this should be treated on the models, not on the TreeView.

Linus - I'm in a Cooking festival now - so cant really hack, but in
the DiveTripModels class inside models.h / cpp there is a method named
columnCount() that returns the amount of columns for a specific item,
you need to change *there*, if you want to make Dives and Trips to
behave differently.

Since the original returns 'COLUMNS' ( the enum value ), it's prepared
to only have COLUMNS rows, change that and profit.

( or maybe not... I'll tinker with that on the next week to see the
possibilities. )

T


More information about the subsurface mailing list