Every QGraphicsItem has a special virtual method QGraphicsItem::paint(). QPainter is passed as an argument. Take a look at docs, there's an example.
Every QGraphicsItem has a special virtual method QGraphicsItem::paint(). QPainter is passed as an argument. Take a look at docs, there's an example.
J-P Nurmi
Could you give me an example?
If I create a QGraphicsPixmapItem, how can i draw inside the item freehand lines?
Thanks!
- subclass/inherit (which ever term you're familiar with) QGraphicsPixmapItem just like you would subclass any class in C++
- reimplement/override (again, which ever term you're familiar with) paint() just like you would reimplement any virtual method in C++, see docs for exact function signature
- in reimplemented paint(), call the base class implementation to paint the pixmap and draw your custom lines afterwards using the painter passed as a parameter
Things like inheritance and member function overriding are not covered by Qt docs. They are basic OOP concepts one should know before one starts working with Qt at all.
J-P Nurmi
william.dias (8th February 2008)
William Dias: Have you tried running the Chip Demo, then holding the secret Shift-button and then clicking and dragging on a chip?
This shows one way to draw freehand on an item. It's one practical approach with source code (chip.cpp) - the item tracks all mouse positions and generates a path by connecting the points.
Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
Nokia Software Manager, Qt Development
william.dias (8th February 2008)
Bookmarks