Results 1 to 4 of 4

Thread: The QAbstractItemModel' data method failed to overwrite background

  1. #1
    Join Date
    Dec 2018
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default The QAbstractItemModel' data method failed to overwrite background

    I have a QTreeView which has a stylesheet applied to items with "QTreeView::item{background-color:#F7F7F7}". The view has a custom model and in the data method, I change the background of some specific cells like this :
    Qt Code:
    1. if (index.column() == 3 && role == Qt::BackgroundColorRole)
    2. {
    3. return QColor("#F4FF81");
    4. }
    To copy to clipboard, switch view to plain text mode 
    But this is not working to overwrite the value set in stylesheet. Is there anyone who can tell me what I miss? Thanks!!!

  2. #2
    Join Date
    Jul 2012
    Posts
    208
    Thanks
    12
    Thanked 14 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The QAbstractItemModel' data method failed to overwrite background

    Stylesheets seem to override and ignore the formatting data coming from the model. See this thread for some suggestions and details:

    https://forum.qt.io/topic/95940/mode...style-sheet/11

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,134
    Thanks
    35
    Thanked 1,477 Times in 1,430 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: The QAbstractItemModel' data method failed to overwrite background

    Either just extend the model to return the other color for the other columns or is a QIdentityProxyModel to supply the "fall back" background color for cells for which the original model didn't provide any.

    Cheers,
    _

  4. #4
    Join Date
    Dec 2018
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: The QAbstractItemModel' data method failed to overwrite background

    thanks a lot. seems I cannot use stylesheet then.

    Thanks a lot. I would try

Similar Threads

  1. QAbstractItemModel for QTreeView with separate data
    By clemens in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2016, 17:46
  2. [solved]QVariant QAbstractItemModel::data()
    By Qiieha in forum Qt Programming
    Replies: 1
    Last Post: 17th July 2015, 11:33
  3. Replies: 4
    Last Post: 5th March 2015, 19:38
  4. QAbstractItemModel reset() method
    By lotek in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2011, 15:55
  5. Replies: 0
    Last Post: 1st September 2011, 14:31

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.