Results 1 to 3 of 3

Thread: How to add custom header to QTableWidget

  1. #1
    Join Date
    May 2014
    Posts
    1
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default How to add custom header to QTableWidget

    How can I add a custom header to my QTableWidget?

    I have derived a class MyHeaderItem from QWidget and QTableWidgetItem and set an instance of it into the table. I have copied the code below.

    This does not work. Column 0 in the table shows an empty header. What am I missing?

    I need a custom header because I want to place several strings and icons in the header.
    Is there some other technique to add a custom header to QTableWidget?


    Qt Code:
    1. class MyHeaderItem : public QWidget, public QTableWidgetItem
    2. {
    3. public:
    4. MyHeaderItem( QWidget* parent ) : QWidget( parent ), QTableWidgetItem( 0 )
    5. {
    6. mWidget.setupUi( this );
    7. }
    8.  
    9. private:
    10. Ui_simple_widget mWidget;
    11. };
    12.  
    13. MyHeaderItem* headerItem = new MyHeaderItem( myTable );
    14. myTable->setHorizontalHeaderItem( 0, headerItem );
    To copy to clipboard, switch view to plain text mode 
    Last edited by alex_25; 20th May 2014 at 22:15. Reason: spelling corrections

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to add custom header to QTableWidget

    If your MyHeaderItem is derived from QWidget, then you need the Q_OBJECT macro in the class definition. Besides that, I have no idea if it is even possible to use a QWidget as a header item. You don't show that you have implemented the clone() method, and I would think that would be an important one.

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

    alex_25 (21st May 2014)

  4. #3
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to add custom header to QTableWidget

    See below link, in which example is given for Hierarchical headers for QTableView, see if it can help you to get some idea for QTableWidget.

    http://qt-apps.org/content/show.php/...content=103154

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

    alex_25 (21st May 2014)

Similar Threads

  1. QTableWidget custom header labels
    By migel in forum Newbie
    Replies: 1
    Last Post: 1st June 2011, 10:20
  2. combo box in Header of QTableWidget
    By sar_van81 in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2008, 17:58
  3. Tooltip on QTableWidget header
    By ghorwin in forum Qt Programming
    Replies: 4
    Last Post: 29th October 2007, 10:34
  4. QTableWidget, header behavior
    By hyling in forum Qt Programming
    Replies: 1
    Last Post: 14th October 2006, 09:03
  5. How to delete header on QTableWidget
    By jlbrd in forum Qt Programming
    Replies: 2
    Last Post: 18th July 2006, 22:00

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.