简体   繁体   English

QTableView不可滚动且文本未包装

[英]QTableView not scrollable and text is not wrapped

I am trying to make something like QtCreator log window. 我正在尝试制作类似QtCreator日志窗口的内容。 I am using QTableView with the following properties: - one column, - horisontalHeaderStretchLastSection = true - horizontalHeaderVisible = false - wordWrap = true - autoScroll = true - horizontalScrollBarPolicy = scrollBarAlwaaysOn 我正在使用具有以下属性的QTableView:-一列, 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: 我得到以下观点:

在此处输入图片说明

This answer worked for me https://stackoverflow.com/a/9547363/458999 这个答案对我有用https://stackoverflow.com/a/9547363/458999

Needed to call resizeRowsToContents after each row insertion 每行插入后需要调用resizeRowsToContents

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM