Results 1 to 2 of 2

Thread: Custom QGraphicsItem paint function problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Default Custom QGraphicsItem paint function problem

    Hello!

    I have a class that inherits QGraphicsItem and QObject:
    Qt Code:
    1. class Foo: public QObject, public QGraphicsItem
    2. {
    3. Q_OBJECT
    4. ...
    5. };
    To copy to clipboard, switch view to plain text mode 
    I have set up a QTimer, and connects its timeout signal with QGraphicsScene's advance.

    I want to display 2 constantly shifting QPixmap on a Foo instance when it is shown:
    Qt Code:
    1. void Foo::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    2. {
    3. painter->drawPixmap(bodyRect, animate?pic1:pic2); // animate is a boolean variable.
    4. if(animate) animate = false;
    5. else animate = true;
    6. }
    To copy to clipboard, switch view to plain text mode 
    e.g., imagine a character walking animation with left foot pixmap and right foot pixmap.

    My problem is, the result shown is not as what i have expected.
    it looks like pic1 is drawn above pic2 or vice versa.
    ( pic1 and pic2 is a .png file, supports transparent background. does that have any effect :? )

    is it impossible to make this, via paint function re-implementation?
    (i'm doing this for learning purposes)

    Thanks for your help and attention!
    Last edited by andzero; 12th October 2011 at 17:25. Reason: missing information

Similar Threads

  1. Help on QGraphicsItem::paint please
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 18th July 2011, 09:11
  2. Custom QStyledItemDelegate paint function never called
    By mattsnowboard in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2011, 02:57
  3. QGraphicsItem paint not triggered
    By roband915 in forum Qt Programming
    Replies: 9
    Last Post: 31st March 2011, 11:06
  4. Qgraphicsitem parent/child paint problem.
    By repka3 in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2009, 23:03
  5. Paint QGraphicsItem problem
    By dreamer in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2008, 19: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.