PDA

View Full Version : sizeHint() called for invisible rows



markusho
10th March 2010, 12:52
I am working on a GUI to display log messages. For this I use a QTableView and a model that inherits from QAbstractTableModel. Each row in the QTableView represents one message. Due to the fact that some messages contain more text than others I have to resize the row height depending on the text length. For this I set the following:


tableView->setWordWrap(true);
tableView->setTextElideMode(Qt::ElideNone);
tableView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);


This works so far. The problem is a performance issue. If I insert one item the sizeHint role is called for all rows (and their columns) in the model - not only for the ones that are visible.
Is there a way to get QT calculate sizes of visible rows only ?

After inserting a new row into the model i called "reset()" in a first version. In my newest version I use "beginInsertRows()" and "endInsertRows()" instead but anyway the sizeHints of all model elements is requested by the view.

aamer4yu
10th March 2010, 13:28
What values you used for "beginInsertRows()" and "endInsertRows()" ??

markusho
10th March 2010, 14:58
I have to add some additional information to answer that. If a message arrives it is stored in a list "m_msgList" which has nothing to do with my QT model. Triggered via a QTimer a method "updateMsgView()" is periodically triggered. This method moves all entries of "m_msgList" to the "m_tableViewList" that is used in the QT Model.
The following code fragment shows the part where the messages are moved to the model list. Even when "m_msgList" contains just one message the sizeHint role of all rows in the model is called.



void updateMsgView(){
...
//append the msgList to the tableViewList
iter = m_tableViewList.end();
beginInsertRows(QModelIndex(),m_tableViewList.size (),m_tableViewList.size() + m_msgList.size() -1);
m_tableViewList.splice(iter,m_msgList);
endInsertRows();

emit signalScrollToBottom();
}



Due to the fact that the content of the messages does not change it should be possible to resize them one time (at the time they are moved to the model).