Results 1 to 4 of 4

Thread: QTableView Background-Color behind Header

  1. #1
    Join Date
    Dec 2015
    Posts
    4

    Default QTableView Background-Color behind Header

    Hey,

    I try to change the color behind the Headers in a QTableView.
    I mean, when I expand the window and the table has more space than I need to display all rows/coloumns there is a white beam beside my last coloum/ under my last row, that doesn't fit to the rest of the colors.

    Thank you in advance.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTableView Background-Color behind Header

    You could try setting the QHeaderView's QPalette entry for the Window ColorRole to match the Button ColorRole:

    Qt Code:
    1. QHeaderView * pHV = myTableView->horizontalHeader();
    2. QPalette pal = pHV->palette();
    3. pal.setBrush( QPalette::Window, pal.brush( QPalette::Button ) );
    4. pHV->setPalette( pal );
    To copy to clipboard, switch view to plain text mode 

    Untested, so no idea if it will work. You could also simply stretch the last column to use up the remaining space:

    Qt Code:
    1. QHeaderView * pHV = myTableView->horizontalHeader();
    2. pHV->setStretchLastSection( true );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Dec 2015
    Posts
    4

    Default Re: QTableView Background-Color behind Header

    At the Moment my QTableView Stylesheet looks like this:
    Qt Code:
    1. /**********TableView**********/
    2. QTableView::enabled{
    3. background-color:lightgrey;
    4. border: 2px solid grey;
    5. border-radius : 4px;
    6. padding: 0 8px;
    7. color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 black,
    8. stop: 1 grey);
    9. }
    10.  
    11. QTableView::!enabled{
    12. background-color:lightgrey;
    13. border: 2px solid grey;
    14. border-radius : 4px;
    15. padding: 0 8px;
    16. color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0
    17. lightgrey, stop: 1 grey);
    18. }
    19.  
    20.  
    21. QHeaderView::section:enabled{
    22. background-color : qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
    23. stop: 0 grey, stop: 1 black);
    24. color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0
    25. lightblue, stop: 1 rgb(93,191,212));
    26. }
    27.  
    28. QHeaderView::section:!enabled{
    29. background-color :qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
    30. stop: 0 grey, stop: 1 white);
    31. color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 black,
    32. stop: 1 grey);
    33. }
    To copy to clipboard, switch view to plain text mode 

    and I hoped that there is a possibility to include the ground behind the header in this stylesheet.

  4. #4
    Join Date
    Dec 2015
    Posts
    4

    Default Re: QTableView Background-Color behind Header

    I found the solution.

    I just had to add

    Qt Code:
    1. background-color: ???
    2. }
    To copy to clipboard, switch view to plain text mode 

    and change these Objects to default, that had been changed automatically by changing QWidget. (Like Line-Edit Background)

Similar Threads

  1. QTableView--keep same background color when selected
    By davethomaspilot in forum Qt Programming
    Replies: 0
    Last Post: 11th February 2014, 17:38
  2. QHeaderView header width and selected background color
    By TheRonin in forum Qt Programming
    Replies: 5
    Last Post: 24th October 2013, 09:18
  3. Setting the background color of a header in TableView
    By sunilqt in forum Qt Programming
    Replies: 1
    Last Post: 13th April 2013, 13:06
  4. Replies: 2
    Last Post: 17th July 2010, 21:07
  5. Replies: 1
    Last Post: 11th September 2009, 17:03

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.