Results 1 to 2 of 2

Thread: Setting Background color for QTableWidget horizontal header

  1. #1
    Join Date
    Sep 2009
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Setting Background color for QTableWidget horizontal header

    I am trying to set the background color for the horizontalHeader of my QTableWidget and nothing seems to work. I have tried setting the background color using setStyle( ) to no effect.

    QHeaderView* header = new QHeaderView( Qt::Horizontal, this );
    QString backgroundStyle = QString( "background-color: rgba(99,0,0,0);\n" );
    header->setStyleSheet( backgroundStyle );
    QTableWidget* contentTable_ = new QTableWidget(this)
    contentTable_->setHorizontalHeader( header );

    I have tried changing the brush for the background color role, no effect.

    QHeaderView* header = new QHeaderView( Qt::Horizontal, this );
    QPalette pp = header->palette();
    pp.setBrush( QPalette::Window, QBrush(QColor(Qt::red)));
    pp.setBrush( QPalette::Background, QBrush(QColor(Qt::red)));
    header->setPalette( pp );
    QTableWidget* contentTable_ = new QTableWidget(this)
    contentTable_->setHorizontalHeader( header );

    I even looked into setting up a delegate for the header so I could override the paint method...nothing (and the documentation even says that QHeaderView ignores delegates).

    Sooo.....is it even possible for me to paint my own header or am I stuck with the light gray default that it currently insists on drawing? I am trying to get 'red' to work for now but ultimately I would like to be able to paint a gradient to the background.

    I'd appreciate any help. Thanks!

  2. #2
    Join Date
    Sep 2009
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Setting Background color for QTableWidget horizontal header

    Figured it out. For those of you who need to be able to do this you can subclass the QHeaderView and reimplement the paintSection member function. I had tried reimplementing 'paint' which doesn't work...but paintSection does.

Similar Threads

  1. How to edit Horizontal Header Item in QTableWidget
    By ioannis in forum Qt Programming
    Replies: 6
    Last Post: 5th March 2013, 19:50
  2. Setting two horizontal header labels for QTablewidget
    By arunvv in forum Qt Programming
    Replies: 2
    Last Post: 20th August 2009, 18:58
  3. setting background color and repositioning
    By mind_freak in forum Qt Programming
    Replies: 2
    Last Post: 11th August 2009, 07:22
  4. QHeaderView: background of selected header item with CSS
    By antarctic in forum Qt Programming
    Replies: 5
    Last Post: 8th June 2009, 08:37
  5. How to customize horizontal header (diagonal header view)
    By vairamuthu.g in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2008, 16:59

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.