Results 1 to 5 of 5

Thread: How to style QTableView headers using stylesheets?

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

    Default How to style QTableView headers using stylesheets?

    Hello,

    I am trying to configure the look of a QTableView widget. I applied a style sheet to my main form which is taken up buy all its children including the QTableView.

    Once I add a model to the QTableView object the headers appear. The colour of the text is according to the style sheet but the background I cannot configure.

    The applied style sheet is:
    *{
    background-color: qlineargradient(spreadad, x1:1, y1:0.813, x2:1, y2:0, stop:0 rgba(87, 87, 87, 255), stop:1 rgba(135,135, 135, 255));
    border: 2px solid gray;
    border-radius: 10px;
    padding: 0 8px;
    color: rgb(255, 255, 255);
    }

    The part of the header without column text is nice with rounded corners and shaded gray, so is the background f the table. The header text is white as it should be but the text background is light gray instead of shaded.
    Please see screen shot below:

    QtableView.jpg

    How can I configure QTableView to have a smooth continues shaded header via style sheets?

    Thanks

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to style QTableView headers using stylesheets?


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

    Default Re: How to style QTableView headers using stylesheets?

    I thought of that. I previously added this:

    QHeaderView {
    background: rgb(255, 255, 127);
    }

    Had no effect what so ever on column heads. However it changed the colour of the header outside of the column heads to yellow.

    Unfortunatelly, the question remains; How do you change the background of the column heads?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to style QTableView headers using stylesheets?

    The example does exactly what you are asking for. You need to style the QHeaderView::section background, not the header view background.

  5. The following 2 users say thank you to ChrisW67 for this useful post:

    FelixB (14th September 2011), mfurqan2202 (24th July 2018)

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

    Default Re: How to style QTableView headers using stylesheets?

    It worked,

    I have not realised that I have to use QHeaderView::section.

    Thank you for your help!

Similar Threads

  1. spaning the headers in the QTableView
    By ru_core in forum Qt Programming
    Replies: 6
    Last Post: 11th June 2013, 14:17
  2. How to remove headers from QTableView.
    By rajeshs in forum Qt Programming
    Replies: 7
    Last Post: 18th November 2011, 21:00
  3. QTableView Headers problem
    By giusepped in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2009, 12:05
  4. swap headers in QTableView
    By dimixan in forum Qt Programming
    Replies: 2
    Last Post: 26th May 2008, 21:44
  5. QTableView : headers disappear
    By xavier in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2006, 17:57

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.