Results 1 to 2 of 2

Thread: How to make table headers with custom background?

  1. #1
    Join Date
    Feb 2010
    Posts
    68
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to make table headers with custom background?

    As in the thread title. I'm using QTableWidget Class to represent data in table.

    I would like these headers:


    To look (for example) like this:


    Is that possible? How to do it?

  2. #2
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make table headers with custom background?

    You can achieve it by using style sheet file.

    Create a file and name it mystyle.qss
    To get custom header :
    Qt Code:
    1. QHeaderView::section {
    2. border: 0.5px solid #C2C7CB;
    3. padding-left: 4px;
    4. background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
    5. stop: 0 #59AAFC,
    6. stop: 0.2 #C2C7CB,
    7. stop: 0.5 #DFDFDF,
    8. stop: 0.7 #C2C7CB,
    9. stop: 1.0 #287ACC );
    10. }
    To copy to clipboard, switch view to plain text mode 

    Set up the style for your app in the main function:
    Qt Code:
    1. int main ( int argc, char* argv[])
    2. {
    3. QApplication app(argc,argv);
    4. QFile file(":/mystyle.qss");
    5. if (file.open(QFile::ReadOnly));
    6. QString styleSheet = QLatin1String(file.readAll());
    7. qApp->setStyleSheet(styleSheet);
    8.  
    9. // other code
    10.  
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    Create a resource file (myresource.qrc) and include your style file:
    Qt Code:
    1. <RCC>
    2. <qresource >
    3. <file>mystyle.qss</file>
    4. </qresource>
    5. </RCC>
    To copy to clipboard, switch view to plain text mode 

    And finally add myresource.qrc in the application *.pro file:
    Qt Code:
    1. RESOURCES = myresource.qrc
    To copy to clipboard, switch view to plain text mode 
    (In this example, the files created are relative to your app directory).
    If you need to customize other widgets just add them to your qss file.

    I encourage you to read about Qt resource and style sheet concepts.
    Have a look at http://doc.trolltech.com/4.6/stylesh...stomizing.html to get more information.
    Last edited by toutarrive; 14th March 2010 at 18:31.

  3. The following user says thank you to toutarrive for this useful post:

    kremuwa (23rd July 2010)

Similar Threads

  1. make background invisible
    By punit.doshi.85 in forum Qt Programming
    Replies: 1
    Last Post: 1st October 2008, 11:48
  2. make install ... no headers?
    By ucntcme in forum Qwt
    Replies: 4
    Last Post: 22nd January 2008, 08:39
  3. How to make headers fixed sized? (QTableWidget)
    By macias in forum Qt Programming
    Replies: 4
    Last Post: 13th August 2007, 16:57
  4. [custom widget] What about private headers ?
    By lauranger in forum Qt Programming
    Replies: 3
    Last Post: 19th November 2006, 00:14
  5. make each row of table widget not editable??
    By darpan in forum Qt Programming
    Replies: 4
    Last Post: 16th October 2006, 11:22

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.