Results 1 to 4 of 4

Thread: QGraphicsItem not repainting

  1. #1

    Default QGraphicsItem not repainting

    Hello,

    I am trying to reimplement the colliding mouse example.
    Everything is the same except
    QMainWindow is used.
    I used the timer event to set new random position on the scene.
    So far so good, I can see my QGraphicsItem on the scene.
    However, the problem is that is not moving..and sometimes parts of the item on the scene will start disappearing. And I can actually 'see the item moving' or moved to a new location if I keep resizing my window or I have a scene->update() command.

    Anybody has any idea why ?

    Thanks !

  2. #2
    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: QGraphicsItem not repainting

    Hard to say without seeing code

    Also u say u are using QMainwindow,,, have u set central widget properly ? and parents of scene and items ? or may be some problem with timer ?

  3. #3

    Default Re: QGraphicsItem not repainting

    Update to what I did..

    I added

    Qt Code:
    1. scene()->update()
    To copy to clipboard, switch view to plain text mode 

    in my QGraphicsItem subclass's timer event method when the item updates its position.
    It solves my repainting issue but felt its a crude way, and I will look for other means to do it.

    On a side note,

    Does anyone know how QGraphicsScene::changed(const QList (QRectf) rect) signal works ?
    What is meant by emits signal scene's content changes ? Does that include position of the QGraphicsItem ?

    How is it used most commonly ?

    Ask quite abit this time but I will keep you guys updated with whatever I find.

    And same as before, Thanks for reading !

  4. #4
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsItem not repainting

    Quote Originally Posted by eijnuhs View Post
    Update to what I did..
    I added
    Qt Code:
    1. scene()->update()
    To copy to clipboard, switch view to plain text mode 
    in my QGraphicsItem subclass's timer event method when the item updates its position.
    It solves my repainting issue but felt its a crude way, and I will look for other means to do it.
    On a side note,
    Does anyone know how QGraphicsScene::changed(const QList (QRectf) rect) signal works ?
    !

    i reload scene by item on this way:

    i need only by move elemenst or rotate , resize (paint outside from rect() item)

    Qt Code:
    1. /* item */
    2. void TextLayer::sceneReload()
    3. {
    4. GraphicsScene *sc;
    5. if (sc = qobject_cast<GraphicsScene *>(scene())) {
    6. sc->clearSelection();
    7. }
    8. }
    9. /* scene */
    10. void GraphicsScene::clearSelection()
    11. {
    12. QGraphicsScene::clearSelection();
    13. /* actual rect sceneRect() or view port */
    14. update(sceneRect());
    15. }
    To copy to clipboard, switch view to plain text mode 

    or i send a setVisibleArea( const QRectF area ) to scene

    Qt Code:
    1. void GraphicsScene::setVisibleArea( const QRectF area )
    2. {
    3. emit MakeVisible(area); /* to GraphicsView */
    4. }
    5.  
    6. void GraphicsView::viewDisplay( const QRectF area )
    7. {
    8.  
    9. /* if scale to big return text no readable */
    10. QMatrix matx = matrix();
    11. qreal HHscaled = matx.m11();
    12. if (HHscaled > 5.1) {
    13. return;
    14. }
    15. QGraphicsView::ensureVisible(area);
    16. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QGraphicsItem doesn't inherit QObject?
    By xyzt in forum Qt Programming
    Replies: 6
    Last Post: 26th September 2011, 14:59
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  3. Problem with rotation of QGraphicsItem
    By ashishsaryar in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2008, 15:03
  4. Snap-to grid on QGraphicsItem
    By hardgeus in forum Qt Programming
    Replies: 9
    Last Post: 28th April 2008, 16:22
  5. Force the painting of a QGraphicsItem
    By fabietto in forum Qt Programming
    Replies: 3
    Last Post: 2nd July 2007, 21: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.