Results 1 to 4 of 4

Thread: Change QTableWidget header name or text

  1. #1
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Change QTableWidget header name or text

    I know it seems a stupid question, but I cannot find how to change QTableWidget header name or text.

    Any idea?

    Thanks.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change QTableWidget header name or text

    take a look at QTableWidget::setHorizontalHeaderLabels and QTableWidget::setHorizontalHeaderItem (in this case you can use QTableWidgetItem::setText).
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change QTableWidget header name or text

    Thanks.

    ui.tableWidgetTextureLibrary->setHorizontalHeaderItem(0, new QTableWidgetItem("Prueba"));
    Worked


    But this one
    ui.tableWidgetTextureLibrary->horizontalHeaderItem(0)->setText("Whatever");
    Doesn't work.

    I mena, instead of creating a new QTableWidgetItem, can I edit the current one?

    Thanks.

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change QTableWidget header name or text

    yes, you can. but at first you have to add an item, because if you don't do this your programm will crash if you use this code:
    Qt Code:
    1. ui.tableWidgetTextureLibrary->horizontalHeaderItem(0)->setText("Whatever");
    To copy to clipboard, switch view to plain text mode 
    so, if you already created an item like this
    Qt Code:
    1. ui.tableWidgetTextureLibrary->setTorizontalHeaderItem(0, new QTableWidgetItem("Whatever"));
    To copy to clipboard, switch view to plain text mode 
    then in you code you can use horizontalHeaderItem for changing column name, because horizontalHeaderItem will return valid pointer.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    ricardo (14th May 2009)

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. How to edit Horizontal Header Item in QTableWidget
    By ioannis in forum Qt Programming
    Replies: 6
    Last Post: 5th March 2013, 19:50
  3. Replies: 1
    Last Post: 3rd September 2008, 15:16
  4. QTableWidget setSpan text display problem
    By sureshbabu in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2008, 17:14
  5. Can't change the text display of a QTreeview item.
    By johnny_sparx in forum Qt Programming
    Replies: 3
    Last Post: 2nd June 2006, 02:03

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.