Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Custom QGraphicsItem paint problem

[Solved] Custom QGraphicsItem paint problem

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andzero
    wrote on last edited by
    #1

    Hello!

    I have a class that inherits QGraphicsItem and QObject:
    @class Foo: public QObject, public QGraphicsItem
    {
    Q_OBJECT
    ...
    };@

    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:
    @void Foo::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    {
    painter->drawPixmap(bodyRect, animate?pic1:pic2); // animate is a boolean variable.
    if(animate) animate = false;
    else animate = true;
    }@
    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!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andzero
      wrote on last edited by
      #2

      Solved! I used update() in a separate function/ slot.

      Thank you! :)

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved