Results 1 to 2 of 2

Thread: Flash Table Cell Background Colour

  1. #1
    Join Date
    Feb 2010
    Location
    Sydney, Australia
    Posts
    111
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Flash Table Cell Background Colour

    I would like to be able to change the background colour (even animate the background colour) of a new item in a ListView when it's added to the model.

    In particular, if a new item is added to the model, I would like it's background colour to be different (the highlight colour) for 5 seconds and then go back to the normal colour. If the highlight colour could fade back to the normal colour, that would be a bonus.

    It would be nice if the colours were dictated by the qss, i.e. not hardcoded.

    I imagined subclassing QStyledItemDelegate with an overidden paint function to draw the background (straightforward). Here is a decent read on QStyledItemDelegate.

    The subclass could have a QTimer (started in the constructor) so that it could decide between painting the background the highlight colour or the normal colour. This only works if a QStyledItemDelegate is created for each cell and I can't work out from the documentation if that is the case. Is there only one instance of the delegate per view or is there one instance per (visible) index?

    This article suggests that there is only one instance of a delegate for multiple similar views, which would mean that the idea of a timer would not work.

    Has anyone got any ideas on how to do this?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Flash Table Cell Background Colour

    QTimer concept will work, QTimer should live in model (or proxy model), Timer is created and started when an row is inserted into model, and it controls the background color over time, and eventually should stop and kill itelf. Also note to emit dataChanged() signal from model when the background color is changed (i.e. every time timer slot executes)

  3. The following user says thank you to Santosh Reddy for this useful post:

    stefanadelbert (28th October 2011)

Similar Threads

  1. Replies: 6
    Last Post: 6th April 2011, 15:33
  2. Calendar Widget - Change cell colour
    By Gavin Harper in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2011, 09:31
  3. Change the colour of a table view row
    By Splatify in forum Newbie
    Replies: 0
    Last Post: 7th March 2011, 07:31
  4. QTextDocument background colour
    By Ruud v A in forum Qt Programming
    Replies: 6
    Last Post: 18th May 2010, 15:30
  5. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 01:44

Tags for this Thread

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.