Results 1 to 10 of 10

Thread: QGraphicsScene::drawItems is not called if it's subclassed

  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 QGraphicsScene::drawItems is not called if it's subclassed

    Hi,

    I have my subclassed graphicsview and graphicsScene, all works perfectly with more or less 100 graphicsitems and some logic implemented in my custom scene.

    I want to control when the items appear, so I tried to subclass QGraphicsScene::drawItems. But when QGraphicsView::drawItems is called it does not go to my subclassed scene, it calls QGraphicsScene::drawItems.

    I can solve it writting my code directly in the view... but I would like to ask if it's the normal behavour or I'm missing something.

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QGraphicsScene::drawItems is not called if it's subclassed

    Quote Originally Posted by jano_alex_es View Post
    But when QGraphicsView::drawItems is called it does not go to my subclassed scene, it calls QGraphicsScene::drawItems.
    QGraphicsView calls drawItems of the scene that is added to the view, thus your custom scene.
    This in turn means that you did something wrong in your scene subclass.

    Post your code.

  3. #3
    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::drawItems is not called if it's subclassed

    QGraphicsView calls drawItems of the scene that is added to the view, thus your custom scene.
    that's the problem... but it doesn't :S


    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. setWindowTitle("PruebaMagnetica1");
    5.  
    6. m_pScene = new CScene();
    7. m_pView = new CView(m_pScene, this);
    8. ...
    9. }
    To copy to clipboard, switch view to plain text mode 

    View.h
    Qt Code:
    1. class CView : public QGraphicsView
    2. {
    3. public:
    4. CView(CScene* pScene, QWidget * parent = 0);
    5. virtual ~CView();
    6.  
    7. void enableRendering(){m_bRender = true;}
    8.  
    9. protected:
    10. void drawItems ( QPainter * painter, int numItems, QGraphicsItem * items[],
    11. const QStyleOptionGraphicsItem options[] );
    12.  
    13. bool m_bRender;
    14. };
    To copy to clipboard, switch view to plain text mode 


    View.cpp
    Qt Code:
    1. CView::CView(CScene* pScene, QWidget * parent)
    2. {
    3. setParent(parent);
    4. setScene(pScene);
    5.  
    6. m_bRender = false;
    7. }
    8.  
    9. CView::~CView()
    10. {
    11. // TODO Auto-generated destructor stub
    12. }
    13.  
    14. void CView::drawItems( QPainter * painter, int numItems, QGraphicsItem * items[], const QStyleOptionGraphicsItem options[] )
    15. {
    16. if(m_bRender)
    17. {
    18. QGraphicsView::drawItems(painter, numItems, items, options); //It calls QGraphicsScene::drawItems instead of CScene::drawItems
    19. m_bRender = false;
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

  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::drawItems is not called if it's subclassed

    How do you know it calls QGraphicsScene::drawItems()?
    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
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: QGraphicsScene::drawItems is not called if it's subclassed

    because I have it subclassed as well in "CScene". But debugging it goes into QGraphicsScene class and not into the subclassed one.

    Scene.h
    Qt Code:
    1. class CScene : public QGraphicsScene
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. CScene(QObject *parent = 0);
    7. virtual ~CScene();
    8.  
    9. protected:
    10. void drawItems ( QPainter * painter, int numItems, QGraphicsItem * items[],
    11. const QStyleOptionGraphicsItem options[] );
    To copy to clipboard, switch view to plain text mode 


    Scene.cpp
    Qt Code:
    1. void CScene::drawItems( QPainter * painter, int numItems, QGraphicsItem * items[], const QStyleOptionGraphicsItem options[] )
    2. {
    3. //
    4. //my code here, with a not called breakpoint
    5. //
    6.  
    7. QGraphicsScene::drawItems(painter, numItems, items, options);
    8. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QGraphicsScene::drawItems is not called if it's subclassed

    Can you post the line of code where you set the breakpoint?
    Some debuggers don't break on certain lines of code.

  7. #7
    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::drawItems is not called if it's subclassed

    I tried using traces as well

    For instance, if I try this in order to test:

    Qt Code:
    1. void CScene::drawItems( QPainter * painter, int numItems, QGraphicsItem * items[], const QStyleOptionGraphicsItem options[] )
    2. {
    3. QGraphicsScene::drawItems(painter, numItems, items, options);//breakpoint
    4. }
    To copy to clipboard, switch view to plain text mode 

    doesn't work either

  8. #8
    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::drawItems is not called if it's subclassed

    just in case, some extra info: I'm using Visual Studio 2008 with Qt 4.5.0 (unfortunatly I can't update)

  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::drawItems is not called if it's subclassed

    Your method has an incorrect signature, you are missing the last argument (QWidget pointer).
    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
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: QGraphicsScene::drawItems is not called if it's subclassed

    buf, I'm so stupid... thanks

Similar Threads

  1. Segfault with subclassed QMdiSubWindow
    By truefusion in forum Newbie
    Replies: 1
    Last Post: 23rd February 2009, 11:56
  2. subclassed const function problem
    By qtneuling in forum Newbie
    Replies: 8
    Last Post: 22nd June 2008, 02:52
  3. how to animate a subclassed widget
    By babu198649 in forum Newbie
    Replies: 4
    Last Post: 31st December 2007, 13:07
  4. setModelData for subclassed QItemDelegate
    By T4ng10r in forum Qt Programming
    Replies: 7
    Last Post: 27th May 2007, 12:09
  5. Subclassed QLabel and enterEvent
    By Lykurg in forum Qt Programming
    Replies: 2
    Last Post: 29th August 2006, 06:44

Tags for this Thread

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.