Results 1 to 2 of 2

Thread: specific painting for just one QGraphicsItem

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default specific painting for just one QGraphicsItem

    Hello, I'm having the next painting code in a QGraphicsPixmapItem:

    Qt Code:
    1. void CFloorMagnet::paint ( QPainter * painter, const QStyleOptionGraphicsItem*
    2. option, QWidget * widget)
    3. {
    4. if(painEllipses)
    5. {
    6. painter->drawEllipse(QPointF(m_iWidth/2, m_iHeight/2),
    7. m_rCurrentLineDistance1, m_rCurrentLineDistance1);
    8. painter->drawEllipse(QPointF(m_iWidth/2, m_iHeight/2),
    9. m_rCurrentLineDistance2, m_rCurrentLineDistance2);
    10. painter->drawEllipse(QPointF(m_iWidth/2, m_iHeight/2),
    11. m_rCurrentLineDistance3, m_rCurrentLineDistance3);
    12. }
    13.  
    14. QGraphicsPixmapItem::paint(painter, option, widget);
    15. }
    To copy to clipboard, switch view to plain text mode 

    it creates three ellipses moving around the pixmap.

    painEllipses variable changes between true-false each 5000 msecs. So, during five seconds I will have the ellipses on the screen and during another five it only draws the pixmap.

    As I'm using QGraphicsView::MinimalViewportUpdate mode, I needed to make bigger the boundingrect in order to make possible that drawing.

    But, when I execute the code the QGraphicsView starts to calculate what doesn't be to be redraw and the first time the painEllipses is false, the ellipses disappear. The second time the ellipses dissapear too but the paint event is called less times and the third try it does not enter. So I have the ellipses on the screen because there is no redraw.

    I can solve if using QGraphicsView::FullViewportUpdate. But due to performance problems QGraphicsView::MinimalViewportUpdate is a must in my view.

    Do you know any way to disable that "smart thinking" just for this item?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: specific painting for just one QGraphicsItem

    Do you call update() when you change the value of painEllipses?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    jano_alex_es (24th March 2011)

Similar Threads

  1. Replies: 5
    Last Post: 14th February 2011, 15:06
  2. QGraphicsItem - painting problem for zoomin
    By nileshsince1980 in forum Qt Programming
    Replies: 0
    Last Post: 26th March 2010, 10:02
  3. [SOLVED] Painting QGraphicsItem constant size
    By JovianGhost in forum Qt Programming
    Replies: 7
    Last Post: 22nd March 2010, 02:25
  4. Replies: 7
    Last Post: 21st March 2010, 04:11
  5. Force the painting of a QGraphicsItem
    By fabietto in forum Qt Programming
    Replies: 3
    Last Post: 2nd July 2007, 22:28

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.