[Qt-interest] QTableWidget - resize header cells

David Boosalis david.boosalis at gmail.com
Tue Aug 4 11:17:58 CEST 2009


This works for me:
int main(int argc, char *argv[])
{
  QApplication app(argc,argv);

  QTableWidget *table = new QTableWidget();
  QStringList headers;
  headers << "SMALL";
  headers << "MEDIUM";
  headers <<"This is a really really long ling header item";
  headers << "Tiny";

  table->setRowCount(20);
  table->setColumnCount(4);
  table->setHorizontalHeaderLabels(headers);
  QHeaderView *horHeader = table->horizontalHeader();
  horHeader->setResizeMode(QHeaderView::ResizeToContents);
  table->show();
  return app.exec();


On Tue, Aug 4, 2009 at 12:08 AM, Eirik Ulvik<eiriku at simsurgery.com> wrote:
> I need to resize headers, both horizontal and vertical, to fit the
> contents. I have tried the resizeColumn/RowToContents, but it does not
> achieve this. I do not know, but maybe these only take into account the
> data cells, not the header cells ? Anyone has a clue to what I should try?
>
> Regards,
> Eirik
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>



More information about the Qt-interest-old mailing list