Results 1 to 4 of 4

Thread: Performance with QTableView and QAbstractTableModel

  1. #1
    Join Date
    Feb 2009
    Location
    Germany, Cologne
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Performance with QTableView and QAbstractTableModel

    Hello,

    At the moment i am developing an apllication for displaying database contents by QTableView and QAbstractTableModel.
    For this purpose i wrote a test application to check the performance. I set only 200 rows and 37 columns but the whole applications slows a bit down. Additionaly the selection of cells is relatively slow.
    Is there any way to increase the performance of this test application?

    Test.h
    Qt Code:
    1. class Model: public QAbstractTableModel
    2. {
    3. Q_OBJECT
    4. public:
    5. Model();
    6. virtual int rowCount( const QModelIndex &parent) const;
    7. virtual int columnCount(const QModelIndex &parent) const;
    8. virtual QVariant data( const QModelIndex &index, int role) const;
    9. QVariant headerData(
    10. int section,
    11. Qt::Orientation orientation,
    12. int role) const;
    13. };
    14.  
    15. class Window: public QMainWindow
    16. {
    17. Q_OBJECT
    18. public:
    19. Window(QWidget *aParent = 0);
    20. private:
    21. QTableView m_view;
    22. Model m_model;
    23. };
    To copy to clipboard, switch view to plain text mode 

    Test.cpp
    Qt Code:
    1. Model::Model()
    2. {
    3. }
    4.  
    5. //
    6. //-----------------------------------------------------------------------------
    7. int Model::rowCount(const QModelIndex &parent) const
    8. {
    9. return 200;
    10. }
    11.  
    12. //
    13. //-----------------------------------------------------------------------------
    14. int Model::columnCount(const QModelIndex &parent) const
    15. {
    16. return 37;
    17. }
    18.  
    19. //
    20. //-----------------------------------------------------------------------------
    21. QVariant Model::data(const QModelIndex &index, int role) const
    22. {
    23. if (role == Qt::DisplayRole)
    24. {
    25. return QVariant(QString("%1, %2 esfgsdgsdgsdgsdg")
    26. .arg(index.row())
    27. .arg(index.column()));
    28. }
    29. return QVariant();
    30. }
    31.  
    32. //
    33. //-----------------------------------------------------------------------------
    34. QVariant Model::headerData(
    35. int section,
    36. Qt::Orientation orientation,
    37. int role) const
    38. {
    39. if (section < 37)
    40. return QVariant(QString("Spalte: %1").arg(section));
    41. else
    42. return QVariant();
    43. }
    44.  
    45. //
    46. //-----------------------------------------------------------------------------
    47. Window::Window(QWidget *aParent):
    48. QMainWindow(aParent),
    49. m_view(this)
    50. {
    51. setCentralWidget(&m_view);
    52. m_view.setModel(&m_model);
    53. m_view.verticalHeader()->setDefaultSectionSize(17);
    54. }
    To copy to clipboard, switch view to plain text mode 

    I hope someone can help me.
    Thanks in advance.

    regards Marco B.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Performance with QTableView and QAbstractTableModel

    setUniformRowHeights(true) on the view will speed things up.

    side note: you should check role in headerData(), too.

  3. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Performance with QTableView and QAbstractTableModel

    doesnt that work only for QTreeView?

  4. #4
    Join Date
    Feb 2009
    Location
    Germany, Cologne
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Performance with QTableView and QAbstractTableModel

    I read from the Qt Assistant that setUniformRowHeights(true) is only available on QTreeViews.
    Looks like there is no way of speeding up my application .

Similar Threads

  1. Replies: 3
    Last Post: 29th January 2009, 09:38
  2. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 14:49

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.