Placing TableWidget Header Labels at runtime
-
When I use this:
ui->tableWidget->horizontalHeaderItem( 0 )->setText( "Last" );
to set my tablewidget header at column 0, I get a seg fault.
However, if I do this:QTableWidgetItem* col0 = new QTableWidgetItem(QString("L Name"),QTableWidgetItem::Type); ui->tableWidget->setHorizontalHeaderItem(0,col0);
it works w/out issue.
Thing is, I'm sure I was doing it the first way a year or so back. Or am I just doing it wrong? The second way I show here is really kind of silly in its long-winded approach just to Label a column.
-
@Driftwood said in Placing TableWidget Header Labels at runtime:
Or am I just doing it wrong?
You did not read the documentation:
"Returns the horizontal header item for column, column, if one has been set; otherwise returns nullptr."
-
Hi
The header uses items also - so they must be allocated.But if you find it a bit clunky there is also
setHorizontalHeaderLabels(const QStringList &labels)
aka
setHorizontalHeaderLabels(QStringList() << "L1" << "L2");
for a shorter version.