Hello,

I have a problem with a QGraphicsItem in a QGraphicsScene. What I would like is to be able to move the item with mouse. But the problem is that in my case, the dragging rectangle is bigger than the item itself.

Here is the code that I use:
Qt Code:
  1. class Test: public QGraphicsView
  2. {
  3. public:
  4. Test();
  5.  
  6. private:
  7. virtual void resizeEvent (QResizeEvent * event);
  8. QGraphicsScene* m_pScene;
  9. };
  10.  
  11. Test::Test()
  12. {
  13. m_pScene = new QGraphicsScene();
  14. setScene(m_pScene);
  15.  
  16. m_pScene->setSceneRect(0, 0, 100, 100);
  17.  
  18. for (int i = 0 ; i < 10 ; i++)
  19. {
  20. pItem->setFlag(QGraphicsItem::ItemIsMovable);
  21. pItem->setBrush(QBrush(QColor(190, 100, 100)));
  22. pItem->setRect(QRectF(10*i, 10, 5, 80.f));
  23. pItem->setCursor(Qt::SizeAllCursor);
  24. m_pScene->addItem(pItem);
  25. }
  26.  
  27.  
  28. setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  29. setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  30.  
  31. resize(600, 200);
  32. fitInView(scene()->sceneRect());
  33. show();
  34. }
  35.  
  36. void Test::resizeEvent(QResizeEvent * event)
  37. {
  38. QGraphicsView::resizeEvent(event);
  39. fitInView(scene()->sceneRect());
  40. }
To copy to clipboard, switch view to plain text mode 

So when I run my program I have this window, and I can drag items. All seems ok.
screen1.jpg

But if I look closer the dragging zone is bigger than the item itself. (see the blue rectangle on following screenshot) The blue rectangle means that If I move the mouse in this rectangle, the cursor changes, and I can drag the item.
screen2.jpg

I have the feeling that the problem is related to the "fitInView(scene()->sceneRect());" line. If I remove the fitInView but adds a scale(5,1) for example, there is the same problem.

Do you have an idea of what the problem could be? Am I doing something wring with coordinates?