Results 1 to 3 of 3

Thread: Custom Tree paint per row

  1. #1
    Join Date
    Aug 2008
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Custom Tree paint per row

    A quick rundown of what I'm trying to accomplish: I have a standardItemModel with two QTreeViews. The first is setup correctly and works fine. The second responds to indirect input. In the main working area, if the user clicks an object, the associations with that object should be visually differentiated. If I click a large blue object and my treeview has 'large' and 'blue' tags in it, I want those strings drawn in different color text.

    My problem comes from the convoluted model/view relationship and the lack of helpful Qt docs. I've read everything there is to regarding itemDelegates over and again, and yet I am still completely in the dark about the basics. It seems that only one delegate is set for a given view so perhaps that isn't what I need. How can this be so hard to do cleanly? I have a model that I've queried, I know that items match, and I know my tree reflects this model. Why can't I say "hey tree! draw this 'item' (or your representation thereof) blue"!?

    As an aside rant, why do standardItems, the direct members of an objectModel, have any sort of visualization functionality? For instance, when prototyping this thing I queried the tree's model for matches and got a list of standardItems. While I can easily change their foreground color, ALL views with this model reflect the changed color. That is not a separation of model and view at all! In my case, I'm ONLY worried about the view.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom Tree paint per row

    Well, you are right till delegates. Further more, you will need to look into syntax highlighters

    Set the highlighter for the delegates, and give the highlighter a list of words that is has to hiighlight ...
    You can refer examples in qt. Also there was xml highlighter by JPN, but i dont remmeber the path. u can search for it on wiki or google.

  3. #3
    Join Date
    Aug 2008
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post

    Unhappy Re: Custom Tree paint per row

    Thank you for the reply.

    After your recommendation, I took a short look at syntax highlighting and I am unsure if it will work for me. I know the trees will have strings (ie. "blue" and "large") repeating even though their underlying items are unique. I only want specific, unique items to highlight which makes me believe syntax highlighting may not work.

    As far as delegates are concerned, I understand more than when I first posted last night but it seems they are still too directly tied to the model. If I understand correctly, when placing items in the model, I can set their data and dataRole. When the delegate draws each item, it determines how and what to draw based on the type of data and/or its role.

    I've tried using an "unset" delegate to draw individual items but I don't know if my code is wrong or the method is incorrect no matter what. By "unset" I mean my view uses the default delegate and I am attempting to call delegate->paint(painter, styleOption, index) on the desired indices. Nothing happens when I do this but perhaps it is immediately overdrawn and I never see it.

    Or more likely, I'm not instantiating my painter or styleOption correctly. All the code examples I've seen are overrides of paint() or drawRow() so the styleOption is already set and passed in as a parameter so I've no idea what about should be set, or when.

    The bottom line is that there simply has to be a more direct, ad hoc way of drawing items in a view.

Similar Threads

  1. Drawing standard widgets using a custom paint engine
    By Waywocket in forum Qt Programming
    Replies: 26
    Last Post: 21st October 2010, 20:40
  2. creating a Tree
    By mickey in forum General Programming
    Replies: 0
    Last Post: 20th April 2008, 17:57
  3. Custom widget
    By zorro68 in forum Qt Programming
    Replies: 7
    Last Post: 28th January 2008, 14:06
  4. Optimizing filterAcceptsRow() to filter a tree
    By vfernandez in forum Qt Programming
    Replies: 1
    Last Post: 4th January 2007, 12:50
  5. paint QTreeView item !!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2006, 14:24

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
  •  
Qt is a trademark of The Qt Company.