Results 1 to 2 of 2

Thread: Custom QGraphicsItem paint function problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Custom QGraphicsItem paint function problem

    The pixmap will be switched each time the paint method is called, this is probably not what you want.
    Connect the timer to a slot, where you will switch the pixmap and update the item:
    Qt Code:
    1. /*slot*/
    2. void Foo::timeout(){
    3. if( this->_pixmap == pixmap1 ){
    4. this->_pixmap = pixmap2;
    5. } else{
    6. this->_pixmap = pixmap1;
    7. }
    8. update();
    9. }
    10.  
    11. void Foo::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    12. {
    13. painter->drawPixmap(bodyRect, this->_pixmap);
    14. }
    To copy to clipboard, switch view to plain text mode 
    Now on each timeout the pixmap will be switched, and item updated, no matter how often its rendered.
    Btw. If you are using Qt >= 4.6, take a look at the QGraphicsObject class.

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

    andzero (13th October 2011)

Similar Threads

  1. Help on QGraphicsItem::paint please
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 18th July 2011, 08:11
  2. Custom QStyledItemDelegate paint function never called
    By mattsnowboard in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2011, 01:57
  3. QGraphicsItem paint not triggered
    By roband915 in forum Qt Programming
    Replies: 9
    Last Post: 31st March 2011, 10:06
  4. Qgraphicsitem parent/child paint problem.
    By repka3 in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2009, 22:03
  5. Paint QGraphicsItem problem
    By dreamer in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2008, 18:18

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.