Results 1 to 5 of 5

Thread: How to change background color of QTableWidget horizontalHeaderItem?

  1. #1
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to change background color of QTableWidget horizontalHeaderItem?

    Hi! I'm trying to change the background color of my QTableWidget horizontal header item but it's not working.

    Qt Code:
    1. QTableWidgetItem *tblCol1 = new QTableWidgetItem("Column 1");
    2. tblCol1->setBackground(Qt::red);
    3. tableWidget->setHorizontalHeaderItem(0, tblCol1);
    To copy to clipboard, switch view to plain text mode 

    Is there other way to do this?

    thanks..

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to change background color of QTableWidget horizontalHeaderItem?

    Works fine here.
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QTableWidget>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7.  
    8. QTableWidget tableWidget(2,2);
    9. QTableWidgetItem *tblCol1 = new QTableWidgetItem("Column 1");
    10. tblCol1->setBackground(Qt::red);
    11. tableWidget.setHorizontalHeaderItem(0, tblCol1);
    12. tableWidget.show();
    13.  
    14. return a.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 
    snapshot1..png

  3. #3
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to change background color of QTableWidget horizontalHeaderItem?

    I've tried to compile the same source code in WINDOWS and LINUX(Ubuntu) using Qt 4.6.1 but both are not working..

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to change background color of QTableWidget horizontalHeaderItem?

    That screen shot is from a Debian Sid box running Qt 4.7 Beta 1. I just tried it on Windows XP running Qt 4.6.2 and the background wasn't changed. indeed!

  5. #5
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: How to change background color of QTableWidget horizontalHeaderItem?

    You can read about Qt Style Sheets, and Customizing QHeaderView.

Similar Threads

  1. Change background color of QPushButton
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2013, 10:23
  2. Replies: 2
    Last Post: 17th July 2010, 21:07
  3. Change frame background color
    By Ishmael in forum Newbie
    Replies: 1
    Last Post: 7th June 2010, 05:38
  4. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14
  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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.