[Qt-interest] Text alignment

Phil phillor at telstra.com
Tue Nov 3 06:08:56 CET 2009


Thank you for reading this.

This is a problem that I have struggled with for some time. A search of the 
archives shows that this question has been asked before but I cannot relate 
the answers to my particular application.

The following code first fills a 6 x 4 table with "x" after which I fill the 
table one row at a time from a list. The code works correctly except that the 
cell contents are left justified no matter what alignment type I use.

This is how I initialise the table.

for(int row = 0; row < 6; row++)
{
  for(int column = 0; column < 4; column++)
  {
    tableItem[row][column] = new QTableWidgetItem("x");
    tableItem[row][column]->setTextAlignment(Qt::AlignHCenter);
  }
}

This is how I add the items from a QStringList list.

for(int col = 0; col < 4; col++)
{
  QTableWidgetItem *item = new QTableWidgetItem(list[col]);
  tableWidget->setItem(row, col, item);
}

Can anyone see where I've gone wrong?
 
-- 
Regards,
Phil



More information about the Qt-interest-old mailing list