Results 1 to 3 of 3

Thread: QTableWidget Background Color

  1. #1
    Join Date
    Sep 2008
    Location
    St. Louis, MO
    Posts
    19
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QTableWidget Background Color

    This code produces a table of toolbuttons (see attachment). How do I set the background color of the table to something other than its default white background?

    #include <QtGui>
    #include <QApplication>

    int main( int argc, char *argv[] )
    {
    QApplication app( argc, argv );

    QDialog *d = new QDialog;
    d->setWindowTitle( "Table Test" );

    QTableWidget *table = new QTableWidget( 2, 3 );
    QStringList headers = QStringList() << "A" << "B" << "C";
    table->setHorizontalHeaderLabels( headers );

    table->setGridStyle( Qt::NoPen );
    table->setCellWidget( 0, 0, new QToolButton );
    table->setCellWidget( 0, 1, new QToolButton );
    table->setCellWidget( 0, 2, new QToolButton );
    table->setCellWidget( 1, 0, new QToolButton );
    table->setCellWidget( 1, 1, new QToolButton );
    table->setCellWidget( 1, 2, new QToolButton );

    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget( table );

    d->setLayout( layout );
    d->show();

    return app.exec();
    }
    Attached Images Attached Images

  2. #2
    Join Date
    Sep 2008
    Posts
    60
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Background Color

    Style sheets might help you. Try calling setStyleSheet("background: rgb(200, 255, 200)") on your table widget.

  3. The following 2 users say thank you to yuriry for this useful post:

    mbrusati (23rd September 2008), rawfool (20th April 2012)

  4. #3
    Join Date
    Nov 2006
    Posts
    23
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget Background Color

    one way is to subclass QTableWidget and repaint the background in the derived classes paint event......

  5. The following user says thank you to Thoosle for this useful post:

    okidoki (30th October 2008)

Similar Threads

  1. Background Image in QTableWidget
    By mclark in forum Qt Programming
    Replies: 11
    Last Post: 6th June 2012, 17:06
  2. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14
  3. how to change QTextEdit background color ?
    By mismael85 in forum Qt Programming
    Replies: 9
    Last Post: 26th June 2008, 22:05
  4. Menu bar background color focus
    By user_mail07 in forum Qt Tools
    Replies: 0
    Last Post: 18th May 2007, 01:25
  5. QLabel background color
    By munna in forum Newbie
    Replies: 3
    Last Post: 1st May 2006, 15:36

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.