Results 1 to 2 of 2

Thread: High cpu usage in custom QItemDelegate::paint

  1. #1
    Join Date
    Apr 2011
    Posts
    61
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default High cpu usage in custom QItemDelegate::paint

    I'm using a QItemDelegate to draw controls in a QListView.
    But, I've found that makes a high cpu usage 80~100% in my computer.

    I think it's happens when I use the buttons, if I have only the progress bar and text there's no high cpu usage.

    I'm using the paint to simulate 6 buttons with icons, a progress and one text in each item.

    (As my code is a big file I've send it as a attachment.)

    Here, my ItemDelegate subclass (only .cpp):
    downloaditemdelegate.cpp

    for the data for the indexes, I'm using this class:
    Qt Code:
    1. #ifndef DOWNLOADITEM_H
    2. #define DOWNLOADITEM_H
    3.  
    4. #include <QObject>
    5. #include <QHash>
    6. #include <QVariant>
    7.  
    8. class DownloadItem : public QObject
    9. {
    10. Q_OBJECT
    11. public:
    12. explicit DownloadItem(QObject* parent = 0);
    13. virtual ~DownloadItem();
    14.  
    15. QVariant data(int a) const { return m_data.value(a); }
    16. void setData(int a, QVariant b) { m_data[a] = b; }
    17.  
    18. private:
    19. QHash<int, QVariant> m_data;
    20. };
    21.  
    22. #endif // DOWNLOADITEM_H
    To copy to clipboard, switch view to plain text mode 

    And if this helps, here a screenshot of the window:
    screenshot_ytdownloader.jpg

    Any ideas to fix it ?
    Is that QHash slow for using data and drawing ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: High cpu usage in custom QItemDelegate::paint

    Calling setData() from within the drawing code is definitely a bad idea. This causes a redraw of the item and your application does nothing but redraws the items over and over again. The model is const in paint() for a reason.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. PyQt4 app : high CPU usage from python and Xorg
    By tipote in forum Qt Programming
    Replies: 3
    Last Post: 30th January 2012, 17:50
  2. High CPU Usage in Drawing
    By lordhippo in forum Qt Programming
    Replies: 15
    Last Post: 21st May 2010, 22:48
  3. QItemDelegate paint() is not called
    By Cortex in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2010, 20:03
  4. Very high CPU usage with QTableView and MVC
    By montylee in forum Qt Programming
    Replies: 7
    Last Post: 24th March 2009, 06:14
  5. Replies: 1
    Last Post: 9th June 2008, 20:41

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.