Results 1 to 8 of 8

Thread: Using QAbstractItemDelegate to display a TGA from a database

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2008
    Posts
    98
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 24 Times in 24 Posts

    Default Re: Using QAbstractItemDelegate to display a TGA from a database

    You may paint to cell blank when you don't have the data, then store the index in an array and use a timer with setSingleShot(true) and the interval you want. Connect the timeout() signal to a slot where you call view->update(index) for all the indexes that need to be repainted.

    Qt Code:
    1. class SQLQueryItemDelegate : public QStyledItemDelegate
    2. {
    3. ...
    4. signals:
    5. void paintingDeferred(const QModelIndex& index);
    6. ...
    7. };
    8.  
    9. class SQLQueryDeferredPainter : public QObject
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. SQLQueryDeferredPainter(QAbstractItemView *view, SQLQueryItemDelegate *delegate, QObject *parent);
    15.  
    16. protected slots:
    17. void paintLater(const QModelIndex& index);
    18. void paintPendingIndexes();
    19.  
    20. protected:
    21. QModelIndexList m_indexes;
    22. QTimer m_timer;
    23. };
    24.  
    25. SQLQueryDeferredPainter::SQLQueryDeferredPainter(QAbstractItemView *view, SQLQueryItemDelegate *delegate, QObject *parent)
    26. : QObject(parent)
    27. {
    28. m_view = view;
    29.  
    30. connect(delegate, SIGNAL(paintingDeferred(const QModelIndex&)),
    31. this, SLOT(paintLater(const QModelIndex&)));
    32.  
    33. m_timer.setSingleShot(true);
    34. m_timer.setInterval(100);
    35. connect(&m_timer, SIGNAL(timeout()),
    36. this, SLOT(paintPendingIndexes()));
    37. }
    38.  
    39. void SQLQueryDeferredPainter::paintLater(const QModelIndex& index)
    40. {
    41. m_indexes.append(index);
    42. m_timer.start();
    43. }
    44.  
    45. void SQLQueryDeferredPainter::paintPendingIndexes()
    46. {
    47. foreach(const QModelIndex& index, m_indexes)
    48. m_view->update(index);
    49.  
    50. m_indexes.clear();
    51. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by victor.fernandez; 28th August 2009 at 07:56. Reason: added example

  2. The following user says thank you to victor.fernandez for this useful post:

    rakkar (28th August 2009)

Similar Threads

  1. Threads and database connection
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 7th August 2013, 08:30
  2. Regarding Database Display through user interface
    By Tavit in forum Qt Programming
    Replies: 1
    Last Post: 1st April 2008, 10:32
  3. Multiple database connections
    By cyberboy in forum Qt Programming
    Replies: 3
    Last Post: 30th March 2008, 16:56
  4. Display only PNG image on desktop
    By durbrak in forum Qt Programming
    Replies: 32
    Last Post: 15th March 2008, 21:55
  5. Database Master-Detail Entry Form
    By Phan Sin Tian in forum Newbie
    Replies: 4
    Last Post: 3rd February 2008, 14:31

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
  •  
Qt is a trademark of The Qt Company.