Results 1 to 3 of 3

Thread: QTableView - resizeRowsToContents() poor performance

  1. #1
    Join Date
    Jun 2009
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTableView - resizeRowsToContents() poor performance

    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

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView - resizeRowsToContents() poor performance

    You could provide the sizeHint through delegate . I guess it will be better than the resizeRowsToContents approach.
    QItemDelegate::sizeHint

  3. The following user says thank you to aamer4yu for this useful post:

    antarctic (8th June 2009)

  4. #3
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QTableView - resizeRowsToContents() poor performance

    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.

    Qt Code:
    1. CommunicationView::CommunicationView( QWidget* parent ) :
    2. QTableView(parent)
    3. {
    4. // Model
    5. m_model = CommunicationModel::instance(this);
    6. setModel(m_model);
    7. // Delegate
    8. m_delegate = new CommunicationDelegate(this);
    9. setItemDelegate(m_delegate);
    10.  
    11. ...
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. CommunicationDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& i ) const
    2. {
    3. CommunicationModel* m_model = (CommunicationModel*)i.model();
    4. CommunicationData::CommunicationDataType type = m_model->type(i.row());
    5. if (type == CommunicationData::VAR_INFO_MESSAGE) {
    6. int const w = QStyledItemDelegate::sizeHint( option, i ).width();
    7. return QSize( w, 34 );
    8. } else {
    9. return QStyledItemDelegate::sizeHint( option, i );
    10. }
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 7th June 2009, 11:47
  2. Very high CPU usage with QTableView and MVC
    By montylee in forum Qt Programming
    Replies: 7
    Last Post: 24th March 2009, 07:14
  3. QTableView in ui with model/delegate
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 7th November 2008, 00:00
  4. QTableView
    By dragon in forum Qt Programming
    Replies: 0
    Last Post: 22nd September 2008, 17:53
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 14:49

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.