qt - Dragging rectangle bigger than item itself using QGrahicsRectItem -


I have a problem in QGrahicsRectItem in QGraphicsScene . What do I want to be able to move the item with the mouse? But the problem is that in my case, the dragging rectangle is bigger than the item.

Here is the code I use:

  class test: public QGraphicsView {public: test (); Private: Virtual Zero resizeEvent (QResizeEvent * Event); QGraphicsScene * m_pScene; }; Test :: Test () {m_pScene = New QGraphicsScene (); SetScene (m_pScene); M_pScene-> Setcreator (0, 0, 100, 100); For (int i = 0; i  SetFlag (QGraphicsItem :: ItemIsMovable); PItem-> Setbrush (QBrush (QColor (190, 100, 100))); PItem-> Set (QRectF (10 * i, 10, 5, 80.f)); PItem-> SetCursor (QT :: SizeAllCursor); M_pScene-> AddItem (pItem); } SetHorizontalScrollBarPolicy (Qt :: ScrollBarAlwaysOff); SetVerticalScrollBarPolicy (QT :: ScrollBarAlwaysOff); Resize (600, 200); FitInView (scene () -> sceneRect ()); Show (); } Zero Test :: resizeEvent (QResizeEvent * Event) {QGraphicsView :: resizeEvent (event); FitInView (scene () -> sceneRect ()); }   

So when I run my program, I have this window, and I can drag the item. Everything looks fine

screen1

But if I look closer than the dragging zone item It is big (see blue rectangle on lower screenshot). The blue rectangle means that if I move the mouse to this rectangle, the cursor changes, and I can drag the item.

screen2

I'm guessing this problem is a " Fit Inview "(view () -> is related to the viewfinder ()); A ???? Line. If I remove it, then it works if I add a scale (5,1) For example, there is only one problem.

Do you know what the problem might be?

I think you kill this bug:

what happens Qi uses a visible rectangle that is in 1x1 size, to test if the items are under the cursor. In your (and my) case, 1 unit in the scene is more than 1 pixel on the screen, so 1x1 covers more than 1 pixel from the rectangular cursor, and touches the items that are not below the cursor.

I submitted a fix / merge request. You can modify your QT source to work for it now.

Comments