Ahmed Waheed
Ahmed Waheed

Reputation: 1291

QTableView not scrollable and text is not wrapped

I am trying to make something like QtCreator log window. I am using QTableView with the following properties: - one column, - horisontalHeaderStretchLastSection = true - horizontalHeaderVisible = false - wordWrap = true - autoScroll = true - horizontalScrollBarPolicy = scrollBarAlwaaysOn

And I use the following code to insert new row into the table

modelView = new QStandardItemModel;
modelView ->setColumnCount(1);
modelView ->setRowCount(0);
ui->tableView->setModel(modelView );

QString msg = "Test Messege 1...................................................................................................................................................................END";
QStandardItem *row = new QStandardItem(msg);
modelView ->setRowCount(window->rowCount()+1);
modelView ->setItem(window->rowCount()-1, 0, row);

However, Neither the text wraps, nor the view is scrollable horizontally, only the content that is within the window size appears.

I get the following view:

enter image description here

Upvotes: 0

Views: 1360

Answers (1)

Ahmed Waheed
Ahmed Waheed

Reputation: 1291

This answer worked for me https://stackoverflow.com/a/9547363/458999

Needed to call resizeRowsToContents after each row insertion

Upvotes: 0

Related Questions