Hi all,

I have a custom QGraphicsItem:


header:
Qt Code:
  1. #ifndef MERCATOR_GRAPHICS_ITEM_H
  2. #define MERCATOR_GRAPHICS_ITEM_H
  3. #include <QPainter>
  4. #include <QGraphicsItem>
  5. #include <QDebug>
  6. #include <QSize>
  7.  
  8. class Mercator_graphics_item : public QGraphicsItem
  9. {
  10. public:
  11. Mercator_graphics_item(QSize size_of_view);
  12.  
  13. QRectF boundingRect() const;
  14. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
  15.  
  16. void resize(QSize new_size);
  17. QSize get_dimension();
  18.  
  19. private:
  20. QSize * size_of_Item;
  21. };
  22.  
  23. #endif // MERCATOR_GRAPHICS_ITEM_H
To copy to clipboard, switch view to plain text mode 


.cpp file:
Qt Code:
  1. #include "mercator_graphics_item.h"
  2.  
  3. Mercator_graphics_item::Mercator_graphics_item(QSize size_of_view)
  4. {
  5. size_of_Item = new QSize(size_of_view.width(),size_of_view.height());
  6. qDebug() << boundingRect();
  7.  
  8. }
  9.  
  10. QRectF Mercator_graphics_item::boundingRect() const
  11. {
  12. return QRectF(0,0,100,100);
  13. }
  14.  
  15. void Mercator_graphics_item::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  16. {
  17. qDebug() << "paint called";
  18. Q_UNUSED(option);
  19. Q_UNUSED(widget);
  20. QRectF map = boundingRect();
  21.  
  22.  
  23.  
  24. painter->drawRect(map);
  25.  
  26. }
  27.  
  28. void Mercator_graphics_item::resize(QSize new_size)
  29. {
  30. *size_of_Item = new_size;
  31. update();
  32. }
  33.  
  34. QSize Mercator_graphics_item::get_dimension()
  35. {
  36. return *this->size_of_Item;
  37. }
To copy to clipboard, switch view to plain text mode 

and this is the method where I create my item:
Qt Code:
  1. ui->setupUi(this);
  2. draw_scene = new QGraphicsScene(this);
  3. Mercator_graphics_item map(ui->graphicsView->size());
  4.  
  5. qDebug() << &map;
  6.  
  7. draw_scene->addItem(&map);
  8. draw_scene->update();
  9. ui->graphicsView->setScene(draw_scene);
To copy to clipboard, switch view to plain text mode 

draw_scene is declared in a different file and it is of type QGraphicsScene *. The problem is that when I run my application nothing is drawn on the graphicsView, and the paint method is not called, I know because the string "print called" (line 17 of .cpp file) is never printed on my console..

Can someone explain me what I'm doing wrong please?

I used the same procedure on another project and in it works well...