Results 1 to 4 of 4

Thread: Paint QGraphicsItem problem

  1. #1
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Paint QGraphicsItem problem

    I'd like to perform a custom painting of my qgraphicsrectitem.
    I don't understand the why the Rect is painted, using this code:

    Qt Code:
    1. void paint (QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget){
    2. QPen p=painter->pen();
    3. painter->setPen(Qt::NoPen);
    4. QGraphicsRectItem::paint(painter,option,widget);
    5.  
    6. /*My Custom Painting*/
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Paint QGraphicsItem problem

    The QGraphicsRectItem has it's pen attribute and use it to draw it's shape.

    you can do this
    Qt Code:
    1. void MyRectItem::paint (QPainter * painter,
    2. const QStyleOptionGraphicsItem * option,
    3. QWidget * widget)
    4. {
    5. QPen p=this->pen();
    6. this->setPen(QPen(Qt::NoPen));
    7. QGraphicsRectItem::paint(painter,option,widget);
    8.  
    9. this->setPen(p);
    10.  
    11. /*My Custom Painting*/
    12. }
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs up Re: Paint QGraphicsItem problem

    ok, thanks!

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Paint QGraphicsItem problem

    You are using - painter->setPen(Qt::NoPen);
    How come u are getting a rect drawn ?? Or u mean the rect shape is filled ??

    Theres a difference between pen and brush. Brush is used to fill the shape, while pen is used to draw lines/shape.

Similar Threads

  1. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 11:31
  2. QT 4.4.0 Upgrade QPainter Problem
    By ChrisReath in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2008, 16:25
  3. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 21:17
  4. Replies: 1
    Last Post: 26th December 2007, 11:58
  5. QGraphicsItem problem - how to save items info ??
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 17th October 2006, 13:17

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.