I've found it. The code should look like this:

Qt Code:
  1. ...
  2. ui->tableWidget->setItem(0, 0, item);
  3. show(); // show the widget so the last column can be resized and the next function will have a proper column size
  4. ui->tableWidget->resizeRowsToContents();
  5. ...
To copy to clipboard, switch view to plain text mode