Results 1 to 3 of 3

Thread: Item Delegate editor background

  1. #1
    Join Date
    Nov 2009
    Posts
    44
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Item Delegate editor background

    I want to set the background for the editor (not the placeholder display created by the paint method) of an Item Delegate. I'm using the Qt::BackgroundRole for the data to set the initial background in the Paint method. But, when the user places focus on the item, and the editor gets drawn, I'd like to use a different background color in the delegate's rectangle. I've tried style sheets and selected color, I've tried setting the palette for the editor, I've tried drawing the background using the selection model's QModel index, but nothing seems to work. What shall I try next? I'm using a QTrieeView, a StandardItemModel and custom data stored in a meta object.

  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: Item Delegate editor background

    Are you using your custom editor ? if yes, editor is also a widget and you can set its background manually.
    Otherwise try using stylesheet for - treeViewClass-->editorClass kind hierarchy...ie editorClass which is child of treeview...try if it works

  3. #3
    Join Date
    Nov 2009
    Posts
    44
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Item Delegate editor background

    I tried all these methods to set the background. Including an idea from another thread that suggested using a slot that processed the selection model's change of current index. None of these worked very well.

    What is working so far is to reimplement the editorEvent and use setData to change the background color role for the model index on gain focus and reset on lose focus (the reset isnt' working yet, but I'll figure it out soon).

    I have a question that I wonder if you can answer... my item delegate is a frame with several child widgets. One of the things I tried was to change the color of the frame panel. The frame's geometry is to cover the whole viewport by default (it seems, anyway since that's what the outline looks like when the editor is drawn). If I change the geometry for the frame in UpdateGeometry, none of the child widgets gets drawn as an active widget - they stay just as a painted representation. Can you explain why that would happen?

Similar Threads

  1. Replies: 2
    Last Post: 12th February 2010, 04:41
  2. Delegate and editor hide event
    By zuck in forum Qt Programming
    Replies: 1
    Last Post: 1st November 2009, 17:59
  3. Replies: 5
    Last Post: 10th August 2009, 10:50
  4. Replies: 2
    Last Post: 5th February 2008, 14:58
  5. Delegate editor sizing problem
    By smacchia in forum Qt Programming
    Replies: 19
    Last Post: 7th December 2007, 16:27

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.