Results 1 to 1 of 1

Thread: `paint` method isn't called after `QGraphicsView` scroll

  1. #1
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    1

    Default `paint` method isn't called after `QGraphicsView` scroll

    Hi, I have a `QGraphicsItem` on scene. `hoverEnterEvent` is reimplemented for this item. This is the code from `hoverEnterEvent`:

    Qt Code:
    1. grabber = new agnt::A_CornerGrabber(A_CornerGrabber::TOP_RIGHT,this,8,3);
    2. assert(grabber);
    3. grabber->installSceneEventFilter(this);
    4. update(boundingRect());
    To copy to clipboard, switch view to plain text mode 
    `A_CornerGrabber` is a class inherited from `QGraphicsRectItem`. The idea is when you hover item a grabber appears so you can drag it to resize main item.

    It works OK until I scroll graphicsview so, that first item is not whole in the view. And afetr this hoverEnterEvent still called, grabber ctor still called, but `grabber->paint()` method isnt called anymore.
    Here is `grabber->paint()`:

    Qt Code:
    1. painter->setPen(Qt::NoPen);
    2. QRectF pRect = parent->boundingRect();
    3. painter->drawRect(rect());
    4. setPos(pRect.bottomRight().x()-size-adjust,pRect.bottomRight().y()-size-adjust);
    To copy to clipboard, switch view to plain text mode 


    sceneEventFilter()

    Qt Code:
    1. if(event->type()== 155)
    2. {
    3. QGraphicsSceneMouseEvent* me = dynamic_cast<QGraphicsSceneMouseEvent*>(event);
    4. if(!me) return true;
    5. if(rect().adjusted(0,0,me->pos().x()-me->lastPos().x(),0).width()>xStep)
    6. {
    7. prepareGeometryChange();
    8. int relX = me->pos().x() - xOffset;
    9. int newRelX = me->lastPos().x() - xOffset;
    10. int steps = relX/xStep;
    11. int newSteps = newRelX/xStep;
    12. setWidth(getWidth()+xStep*(steps-newSteps));
    13. setInitialTime(QString::number(getTime().toInt()+(steps - newSteps) ) );// my func
    14. }
    15. }
    16. if(event->type()== 187)
    17. {
    18. dynamic_cast<agnt::A_GntGV*>(scene()->views().at(0))->timeChanged(getT(),getId());
    19. //my func, has nothing to do with painting
    20. }
    21.  
    22. if(event->type()==160||event->type()==162)
    23. return false;
    24. return true;
    To copy to clipboard, switch view to plain text mode 

    Why is that?


    P.S. Everything worked fine some time ago before I made some changes to my code. Unfortunately I can't restore old code and I cant understand what exactly spoiled `grabber->paint()`.

    Thanks

    EDIT: I think sceneEventFilter() doesnt even matter. The problem persist if I comment
    Qt Code:
    1. //grabber->installSceneEventFilter(this);
    To copy to clipboard, switch view to plain text mode 
    Last edited by rippa; 20th September 2012 at 08:02.

Similar Threads

  1. Custom QStyledItemDelegate paint function never called
    By mattsnowboard in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2011, 01:57
  2. QTextedit scroll or paint problem
    By pavanbarot in forum Qt Programming
    Replies: 0
    Last Post: 29th December 2010, 13:22
  3. QItemDelegate paint() is not called
    By Cortex in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2010, 20:03
  4. QObject's event method not being called
    By jkburges in forum Qt Programming
    Replies: 1
    Last Post: 4th September 2009, 09:02
  5. paint method
    By zgulser in forum Newbie
    Replies: 6
    Last Post: 20th July 2009, 08:57

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.