Results 1 to 8 of 8

Thread: Dynamically change style sheeted QTableView row background color

  1. #1
    Join Date
    Oct 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Dynamically change style sheeted QTableView row background color

    I'm trying to implement 'blinking row background' in QTableView. I initially wanted to implement this by:



    The problem I have is the QTableView is customized by style sheets. So the style class implementation does not use QStyleOptionViewItemV4::backgroundBrush property when its drawing the background.

    What would be a proper approach for me to use in this case?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamically change style sheeted QTableView row background color

    A proper approach would be to not overuse style sheets.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dynamically change style sheeted QTableView row background color

    Can you please elaborate what you mean by "overuse stylesheets" here? There is already working application where stylesheets were used to give the application nice look. I thought it is exactly the way stylesheets are supposed to be used.

    Now I have to make a minor change to the application (well I thought it would be minor, but apparently its not): make rows of one of the table views to blink in some special cases.

    Do you think the only way now is to get rid of the stylesheets in the entire application?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamically change style sheeted QTableView row background color

    Quote Originally Posted by topoden View Post
    Can you please elaborate what you mean by "overuse stylesheets" here?
    I mean total restyling of your application only using stylesheets.

    Now I have to make a minor change to the application (well I thought it would be minor, but apparently its not): make rows of one of the table views to blink in some special cases.
    You can make them blink. They just won't follow stylesheets anymore. Hence my original answer.

    Do you think the only way now is to get rid of the stylesheets in the entire application?
    No, I mean you should style your table with a custom delegate and not stylesheets. You can use stylesheets for other things.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dynamically change style sheeted QTableView row background color

    No, I mean you should style your table with a custom delegate and not stylesheets. You can use stylesheets for other things.
    Did I get it right that for this particular table I need to disable stylesheets and do the entire drawing in the delegate? What would be the way to disable the stylesheets for a particular QTableView regardless of how complex parent widget's stylesheets are? The stylesheets can be cascading to the table from several parents. Do I have to amend selectors for all of them?
    Last edited by topoden; 21st May 2013 at 15:06.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamically change style sheeted QTableView row background color

    You don't need to disable stylesheets. Just don't style items or ignore that they do have any style. If you implement your own delegate and not call the base class implementation, items in the table will not be styled by stylesheets.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Oct 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dynamically change style sheeted QTableView row background color

    Got it, but is it possible to somehow work around implementing the entire drawing by myself but calling the base class's method with a hint not to use stylesheets? Say, in debugger I see it takes the style to draw with from QStyleOptionViewItemV3::widget property. Do you think it can be right to amend this property somehow in the sub-classed delegate paint method and then call base class's one?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamically change style sheeted QTableView row background color

    If you use QItemDelegate instead of QStyledItemDelegate (which is the default) then stylesheets will not be used in items.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    topoden (21st May 2013)

Similar Threads

  1. cannot change QLCDNumber background color
    By saman_artorious in forum Qt Programming
    Replies: 2
    Last Post: 13th March 2013, 16:04
  2. Dynamically change existing curve color
    By missoni in forum Qwt
    Replies: 2
    Last Post: 19th June 2012, 11:32
  3. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14
  4. how to change background color of QMenu??
    By anupamgee in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2009, 12:41
  5. Change background color for a QPushButton?
    By Harvey West in forum Qt Programming
    Replies: 6
    Last Post: 5th January 2007, 14:23

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.