Results 1 to 3 of 3

Thread: QPainter and QGraphicsScene

  1. #1
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QPainter and QGraphicsScene

    Hello all,

    I am trying to create an application to draw lines of force given several point charges. To do so, I have set up the following:

    MainWindow with a QGraphicsView, to which I assign a QGraphicsScene.

    I then have a QGraphicsEllipseItem derived class (Charge), of which I derive several instances and add them to the scene.

    Each instance of the Charge class has a list of curved lines each defined as a list of QPointF's.

    I use the paint() event to paint the objects along with their respective curved lines.

    The issue I am running across is this:

    The set of curved lines emerging from each Charge object are supposed to be different. When I draw them, however, they all display identically. In other words, each object ends up with the same curved line(s) drawn relative to that object. My calculations are correct. Each Charge object does have a different list of points for each of the curved lines.

    The core of the problem, I think I have discovered, is the fact that each time paint() gets called on one of the Charge objects, whoever is doing the calling is passing the same QPainter object. It looks to me like if I try to draw one Charge object, then draw a separate object in another location, somehow the second object ends up being a carbon copy of the first, rather than being drawn with its own characteristics. Or vice-versa, I'm not sure which.

    Anyway, does anybody have any suggestions on a better approach, or how to make this approach work, so that I can draw each of my custom objects independently?

  2. #2
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: QPainter and QGraphicsScene

    could you precise with problematic piece of code

  3. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPainter and QGraphicsScene

    The single painter seems correct, in the end you have only one scene on which you draw all your objects.

Similar Threads

  1. QPainter in QGraphicsScene
    By mukunda in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2011, 07:35
  2. QPainter in QGraphicsScene
    By mukunda in forum Qt Programming
    Replies: 1
    Last Post: 24th January 2011, 16:28
  3. QGraphicsScene vs QPainter techniques
    By zotu in forum Newbie
    Replies: 3
    Last Post: 23rd October 2010, 09:55
  4. QPainter error saving an image from a QGraphicsScene
    By cydside in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2010, 04:53
  5. Replies: 3
    Last Post: 30th April 2006, 19:22

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.