Results 1 to 3 of 3

Thread: Models, Views, and Styling

  1. #1
    Join Date
    Mar 2011
    Posts
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Models, Views, and Styling

    I'm really struggling with some of the model/view structures in Qt. In particular, I don't understand why the model is controlling the appearance. The "data" method returns visual styling information for the various roles, which means that all of the views on that model share the same presentation, which makes no sense if the purpose of the model and view separation is to isolate the model from its presentation.

    When I started looking into QStyledItemDelegate, I thought it was the answer to my problem. I understand that I can use it to take over the drawing, but I don't want or need to completely handle the painting. I just need to set colors and fonts for the roles (exactly as the model is doing, but independently of the model). I don't see how to do that using a delegate unless I also draw every item myself.

    This is driving me nuts. Am I missing something?

    Doug

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Models, Views, and Styling

    You could use a view-specific QAbstractProxyModel between the real model and the view to basically override the presentation role values that are being returned by the real model. Override the data() method to either return your own presentation setting or call the wrapped model's own data() method where desired.

  3. #3
    Join Date
    Mar 2011
    Posts
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Models, Views, and Styling

    The proxy model ended up working out pretty well for the presentation. It eliminates the concerns I had, and since I'll need sorting and/or filtering, it makes sense to include it now.

    Thanks,
    Doug

Similar Threads

  1. Editable Models
    By MTK358 in forum Newbie
    Replies: 1
    Last Post: 9th September 2010, 19:58
  2. Problems with selection models & views
    By russdot in forum Qt Programming
    Replies: 3
    Last Post: 11th August 2009, 03:13
  3. sql models
    By damiano19902 in forum Newbie
    Replies: 1
    Last Post: 4th June 2009, 07:18
  4. Proxy models and slection models
    By amunitz in forum The Model-View Framework
    Replies: 1
    Last Post: 23rd September 2008, 14:35
  5. Models, delegates or views and how?
    By maddogg in forum Newbie
    Replies: 3
    Last Post: 9th November 2007, 13:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.