Results 1 to 5 of 5

Thread: QTableView - selected item colors

  1. #1
    Join Date
    Jul 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTableView - selected item colors

    Hi Folks...

    I have a QTableView that I populate with data from a model. The model specifies some foreground/background coloring for a given cell in the table based on the content of the cell...

    What I cannot figure out how to do is control the coloring of items/rows when they are selected. All coloring that I assign using Qt::ForegroundRole and Qt::BackgroundRole are ignored if the item is selected...

    Are there comparable tags for selected item foreground/background role? I did look into using stylesheets for manipulating selected item colors but they don't seem to be sensitive to the content of a cell.

    Thanks for any pointers in the right direction...

    -G

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTableView - selected item colors

    the selection color is defined by the palette of the view. See QPalette::Highlight and QPalette::HighlightText

  3. #3
    Join Date
    Jul 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView - selected item colors

    Thanks Lykurg...

    But, what I'm still not quite understanding is how I would actually use that...

    Let's say, for instance, I am setting a row of text in my table view to have a Qt::ForegroundRole of "red" due to some condition in the underlying model... Let's say the remaining rows in the table default to "black".

    When the user selects a given row, am I supposed to then manipulate the palette for the table?

    If that is the right way, at which point would I attempt to do this? When the selection model indicates that the selection has changed? Or on the QTableView click() event that would preceed it?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTableView - selected item colors

    The palette of the view is a permanent setting. So set the colors when you define your view. The selection color is used for all items regardless on the foregroundrole. If you need more specific color settings, you have to use a delegate where you could manipulate the used colors.
    Qt Code:
    1. QPalette p = yourView->palette();
    2. //set colors
    3. yourView->setPalette(p);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jul 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView - selected item colors

    That is what I was afraid of!

    vielen dank!

Similar Threads

  1. QTableView item selected signal?
    By sherbs in forum Newbie
    Replies: 7
    Last Post: 3rd August 2010, 15:02
  2. popupmenu for QTreeWidget's item when a particular item selected.
    By vinod sharma in forum Best Practices in Qt Programming
    Replies: 1
    Last Post: 22nd January 2010, 10:45
  3. Replies: 1
    Last Post: 20th January 2010, 08:38
  4. How to set selected item of a QListWidget?
    By Lawand in forum Qt Programming
    Replies: 9
    Last Post: 5th April 2009, 11:23
  5. combobox and item colors
    By zorro68 in forum Qt Programming
    Replies: 16
    Last Post: 23rd September 2007, 12:54

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.