Results 1 to 3 of 3

Thread: QItemDelegate paint() is not called

  1. #1
    Join Date
    Oct 2009
    Posts
    14
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Exclamation QItemDelegate paint() is not called

    Hi,

    Am trying to subclass an item Delegate (to display images on QTableView cells),
    I reimplemented QItemDelegate::paint() and QItemDelegate::sizeHint().
    When I tested it, the function paint() is not called at all.
    Here is my code


    Qt Code:
    1. class ItemImageDelegate : public QItemDelegate
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. ItemImageDelegate(QObject*) ;
    7.  
    8. void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
    9. QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const;
    10. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. ItemImageDelegate::ItemImageDelegate(QObject *parent = 0) : QItemDelegate(parent) {}
    2.  
    3.  
    4. void ItemImageDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
    5. {
    6. qDebug()<<"Paint called";
    7. }
    8.  
    9. QSize ItemImageDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
    10. {
    11. qDebug()<<"Size Hint called";
    12. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // Main class
    2. // setting the model ...
    3. QTableView* view = new QTableView();
    4. view->setModel(model);
    5. ItemImageDelegate delegate(this);
    6. view->setItemDelegate(&delegate);
    7. view->resizeColumnsToContents();
    8.  
    9. view->show();
    To copy to clipboard, switch view to plain text mode 

    It seems so wierd to me, am for sure missing something, but I can't figure it out
    Please help

    Happy coding for all !!

  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: QItemDelegate paint() is not called

    You are creating your delegate on the stack so it goes out of scope and is destroyed. Create it on heap instead.
    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.


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

    Cortex (10th January 2010)

  4. #3
    Join Date
    Oct 2009
    Posts
    14
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QItemDelegate paint() is not called

    Wysota you're a life saver

Similar Threads

  1. Destructor not being called
    By vieraci in forum Qt Programming
    Replies: 12
    Last Post: 25th January 2012, 15:06
  2. How come this slot doesn't get called every second?
    By ShaChris23 in forum Qt Programming
    Replies: 2
    Last Post: 5th November 2009, 23:41
  3. Why Qt is called Qt?
    By nifei in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2009, 07:40
  4. Slot gets called twice
    By greatgatsby in forum Newbie
    Replies: 7
    Last Post: 20th August 2009, 15:11
  5. SLOT not being called
    By steg90 in forum Qt Programming
    Replies: 4
    Last Post: 6th December 2007, 11:30

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.