You don't need line 23 in your original post.

Maybe:
Qt Code:
  1. table->horizontalHeader()->setStretchLastSection(true);
  2. OR
  3. table->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
To copy to clipboard, switch view to plain text mode 
are more to your liking?