area51
8th October 2009, 16:51
Hi,
I'm using a QStandardItemModel with QStandardItems to fill a QTableView. (Qt 4.5.2 on Debian Linux)
QTableView *table = new QTableView();
QStandardItemModel *model = new QStandardItemModel(num_rows, num_cols);
//add a header for column 0
QStandardItem *header_item = new QStandardItem("Some Title");
model->setHorizontalHeaderItem(0, header_item);
//add more headers and items to the model.....
//now let the columns resize to fit their contents
table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
table->setModel(model);
The problem occurs when I set the size of the columns to stretch automatically to its contents, but then the content of the headers itself does not fit.
It seems only the contents of the actual data rows are used for stretching.
How can I stretch the horizontal headers in a way that it will also fit the text inside the headers?
Note that the text inside the headers are displayed in a slightly larger and bold font.
The same things happen when I use: table->resizeColumnToContents(0);
Thank you in advance
I'm using a QStandardItemModel with QStandardItems to fill a QTableView. (Qt 4.5.2 on Debian Linux)
QTableView *table = new QTableView();
QStandardItemModel *model = new QStandardItemModel(num_rows, num_cols);
//add a header for column 0
QStandardItem *header_item = new QStandardItem("Some Title");
model->setHorizontalHeaderItem(0, header_item);
//add more headers and items to the model.....
//now let the columns resize to fit their contents
table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
table->setModel(model);
The problem occurs when I set the size of the columns to stretch automatically to its contents, but then the content of the headers itself does not fit.
It seems only the contents of the actual data rows are used for stretching.
How can I stretch the horizontal headers in a way that it will also fit the text inside the headers?
Note that the text inside the headers are displayed in a slightly larger and bold font.
The same things happen when I use: table->resizeColumnToContents(0);
Thank you in advance