If I add my subclassed QGraphicsItem before I add anything else to the scene everything works fine. But if I add something else before then the paint method is never triggered in my new QGraphicsItem. Can somebody explain what I am missing?


Qt Code:
  1. MyScene::MyScene(QObject *parent)
  2. : QGraphicsScene(parent), currentDrawItem(NULL), bDraw(false)
  3. {
  4. void MyScene::toggleSymbols()
  5. {
  6. if(bSymbols)
  7. {
  8. qDebug("false");
  9. bSymbols = false;
  10. }
  11. else
  12. {
  13. qDebug("true");
  14. bSymbols = true;
  15. symbols = new itemSymbols(); //Subclassed QGraphicsItem
  16. QPointF centerPos = QPointF(this->sceneRect().width()/2, this->sceneRect().height()/2);
  17. symbols->setCenterPos(centerPos);
  18. addItem(symbols);
  19. }
  20. }
  21. }
To copy to clipboard, switch view to plain text mode 


Qt Code:
  1. itemSymbols::itemSymbols() : QGraphicsItem()
  2. {
  3. void itemSymbols::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  4. {
  5. Debug("itemSymbols paint()");
  6. }
  7. }
To copy to clipboard, switch view to plain text mode