View Full Version : Change QTableWidget header name or text
ricardo
14th May 2009, 12:21
I know it seems a stupid question, but I cannot find how to change QTableWidget header name or text.
Any idea?
Thanks.
spirit
14th May 2009, 12:25
take a look at QTableWidget::setHorizontalHeaderLabels and QTableWidget::setHorizontalHeaderItem (in this case you can use QTableWidgetItem::setText).
ricardo
14th May 2009, 12:34
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.
spirit
14th May 2009, 12:37
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:
ui.tableWidgetTextureLibrary->horizontalHeaderItem(0)->setText("Whatever");
so, if you already created an item like this
ui.tableWidgetTextureLibrary->setTorizontalHeaderItem(0, new QTableWidgetItem("Whatever"));
then in you code you can use horizontalHeaderItem for changing column name, because horizontalHeaderItem will return valid pointer.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.