Results 1 to 3 of 3

Thread: How to add custom header to QTableWidget

Threaded View

Previous Post Previous Post   Next Post Next Post
  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 21:15. Reason: spelling corrections

Similar Threads

  1. QTableWidget custom header labels
    By migel in forum Newbie
    Replies: 1
    Last Post: 1st June 2011, 09:20
  2. combo box in Header of QTableWidget
    By sar_van81 in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2008, 16:58
  3. Tooltip on QTableWidget header
    By ghorwin in forum Qt Programming
    Replies: 4
    Last Post: 29th October 2007, 09:34
  4. QTableWidget, header behavior
    By hyling in forum Qt Programming
    Replies: 1
    Last Post: 14th October 2006, 08:03
  5. How to delete header on QTableWidget
    By jlbrd in forum Qt Programming
    Replies: 2
    Last Post: 18th July 2006, 21: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.