PDA

View Full Version : QTableView - resizeRowsToContents() poor performance



antarctic
8th June 2009, 03:20
Hi !

resizeRowsToContents() and/or resizeColumnsToContents() for a QTableView has a dramatically negative performance impact (at least in version 4.3.3) at creation of the model and view. (10000 rows over a second. without the resize...() it is shown immediately)

Any experiance how this can be improved ? (Header, Delegator, CSS ?)

thanks,
Bernd

aamer4yu
8th June 2009, 06:30
You could provide the sizeHint through delegate . I guess it will be better than the resizeRowsToContents approach.
QItemDelegate::sizeHint

schall_l
11th December 2009, 14:13
I also have a QTableView and I am using a custom delegate that derives from QStyledItemDelegate.

I want to change the height of the QTableView row depending on the item that get's added to the model.

I've tried reimplementing the sizeHint() function of QStyledItemDelegate class but it's not getting invoked at all.

I would like to avoid to invoke resizeRowsToContents() each time something gets added to the model as the model does contain a lot of datas.


CommunicationView::CommunicationView( QWidget* parent ) :
QTableView(parent)
{
// Model
m_model = CommunicationModel::instance(this);
setModel(m_model);
// Delegate
m_delegate = new CommunicationDelegate(this);
setItemDelegate(m_delegate);

...


QSize
CommunicationDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& i ) const
{
CommunicationModel* m_model = (CommunicationModel*)i.model();
CommunicationData::CommunicationDataType type = m_model->type(i.row());
if (type == CommunicationData::VAR_INFO_MESSAGE) {
int const w = QStyledItemDelegate::sizeHint( option, i ).width();
return QSize( w, 34 );
} else {
return QStyledItemDelegate::sizeHint( option, i );
}

}