• Is there any way I can have different tableview header for two different view from same model.
    I want for one view my header should be a b c but for other i want my header should be x y z. I dont know how to use custom role in Model::headerData(), can any one please give me some clue,
    code would be great help

  • I do that by inserting a custom proxy model between the view and the model (e.g. QSortFilterProxyModel subclass if you want its features anyway) and providing the headers there.

  • Yes we talked about that but due to some reason I have been told not to use proxy thing due to some performance hit because proxy does maping and since model is big it hits the performance.
    Could there be any other way around?

  • QSortFilterProxyModel has a performance hit due to some internal duplication for mapping, but the generic QAbstractProxyModel can be taylored to not duplicate any data.

  • DerManu: what you are saying might be quite possible, but what I am thinking here is headerData() has one parameter role, I am kind of wondering how can i set custom role so that for one custom role it should return me one set of value and for other it should return other set of value.
    I am not sure but I think if I am able to set this role thing I might have my solution, what do you experts say?

  • Just use QIdentityProxyModel as your base class for your proxy then. It's mapping is trivial, so there is only a minimal performance penalty.

  • Andre: Okay but without using proxy could there be any way to have different header for two different view from same model?
    I see a role paramenter in headerData() but I coiuld not find any way to set that looks like I am missing something, can you guys help?

  • I am wondering how can i use Qt::userRole here.

  • [quote author="Immii" date="1341867904"]I am wondering how can i use Qt::userRole here.[/quote]

    Not at all.

    Why do you make it so difficult for yourself? The proxy method really is the simplest route.

    An alternative could be to "just" create your own QHeaderView subclasses and render the headers yourself without using the model at all, but it is a much more complex route than using a trivial proxy model. And no, trying to use a delegate on the header is not going to work either.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.