Results 1 to 12 of 12

Thread: QGraphicsScene::drawForeground()

  1. #1
    Join Date
    Aug 2009
    Posts
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsScene::drawForeground()

    How to make the QGraphicsScene to redraw it's foreground?

    I've tried:
    QGraphicsView::invalidateScene()
    QGraphicsView::updateSceneRect()
    QGraphicsScene::invalidate()
    QGraphicsScene::update()

    but it only calls QGraphicsView::drawForeground(), and never the QGraphicsScene::drawForeground(). Can someone tell me where can be the problem? Thanks ...

    Tomas

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene::drawForeground()

    Quote Originally Posted by alpinista View Post
    How to make the QGraphicsScene to redraw it's foreground?
    I've tried:
    QGraphicsView::invalidateScene()
    QGraphicsView::updateSceneRect()
    QGraphicsScene::invalidate()
    QGraphicsScene::update()
    but it only calls QGraphicsView::drawForeground(), and never the QGraphicsScene::drawForeground(). Can someone tell me where can be the problem? Thanks ..
    How do you know that QGraphicsScene::drawForeground() is never getting called ?

  3. #3
    Join Date
    Aug 2009
    Posts
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsScene::drawForeground()

    How do you know that QGraphicsScene::drawForeground() is never getting called ?
    I have my own scene class derived from QGraphicsScene, with reimplemented drawForeground() and some printf() inside ...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QGraphicsScene::drawForeground()

    Do you have CONFIG+=console in your project file? Did you make sure the signature of the method is identical to the original one?
    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.


  5. #5
    Join Date
    Aug 2009
    Posts
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsScene::drawForeground()

    Quote Originally Posted by wysota View Post
    Do you have CONFIG+=console in your project file? Did you make sure the signature of the method is identical to the original one?
    yeah, i'm pretty sure about it ... but anyway, QGraphicsView::drawForeground() and QGraphicsView::drawBackground() are called allways, no matter which layer is set when calling QGraphicsScene::invalidate(). That's strange, isn't it?

  6. #6
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene::drawForeground()

    Hi

    Are your sure you set the scene for the graphicsview with QGraphicsView::setScene ?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QGraphicsScene::drawForeground()

    No, it's not strange. If something is modified on the scene, the background and foreground need to be repainted as well. You do want to see them, right? If you only repainted the layer that changed, you wouldn't see the other two layers because... they would not be painted.

    Please provide some code so that we can see if you didn't do any mistakes.
    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.


  8. #8
    Join Date
    Aug 2009
    Posts
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsScene::drawForeground()

    ok .. here's the code:

    scene class (not complete..):
    Qt Code:
    1. /**
    2.  *
    3.  *
    4.  */
    5. class CScene : public QGraphicsScene
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. CScene(QObject* parent = NULL);
    11. ~CScene();
    12.  
    13. CViewHelper* getHelper();
    14. CViewMarker* getMarker();
    15.  
    16. void clearAll(void);
    17. void clearSelected(void);
    18. void clearAuxiliary(void);
    19.  
    20. void print(QPrinter* printer);
    21. bool isPrinting(void);
    22.  
    23.  
    24. protected:
    25. virtual void drawForeground(QPainter* painter, const QRectF & rect);
    26. virtual void drawBackground(QPainter* painter, const QRectF & rect);
    27.  
    28.  
    29.  
    30. private:
    31.  
    32. CViewHelper* _helper;
    33. CViewMarker* _marker;
    34.  
    35. // and some other private attributes ...
    36.  
    37. };
    To copy to clipboard, switch view to plain text mode 


    the definition of drawForeground:
    Qt Code:
    1. void CScene::drawForeground(QPainter* painter, const QRectF & rect)
    2. {
    3. printf(" >>>> SCENE ---> draw foreground\n");
    4.  
    5. // draw helper
    6. if (_helper->isEnabled())
    7. _helper->draw(painter);
    8.  
    9. // draw marks
    10. if (_marker->isEnabled())
    11. _marker->draw(painter);
    12. }
    To copy to clipboard, switch view to plain text mode 


    I'am trying to redraw scene foreground by mouse move event (just now, for debugging). CGView is derived from QGraphicsView.
    Qt Code:
    1. void CGView::mouseMoveEvent(QMouseEvent *event)
    2. {
    3. _ddirector->mouseMove(event);
    4.  
    5. scene()->invalidate(scene()->sceneRect(), CScene::ForegroundLayer);
    6. }
    To copy to clipboard, switch view to plain text mode 

    anyway, thanks for trying me to help ...

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QGraphicsScene::drawForeground()

    And how come (apart from the printf) you know the method is not called? BTW. Call update() instead of invalidate and see if anything changes.
    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.


  10. #10
    Join Date
    Aug 2009
    Posts
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsScene::drawForeground()

    Quote Originally Posted by wysota View Post
    And how come (apart from the printf) you know the method is not called?
    I know it, becouse the _helper->draw() or _helper->isEnabled() (see the code) are not called too .. And I also use the breakpoints.

    And QGraphicsScene::update() doesn't change anything

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

    Default Re: QGraphicsScene::drawForeground()

    I'm absolutly lost with your problem... have you tried rebuilding the project? :S

  12. #12
    Join Date
    Aug 2009
    Posts
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsScene::drawForeground()

    I think I know what's wrong. I have also reimplemented QGraphicsView::drawForeground() and I didn't know that this is the method which actually calls QGraphicsScene::drawForeground(). Am I right?

    So I would like to close this thread and thank to everyone for help
    Have a nice weekend

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.