Qt - In QGraphicsScene, I cannot get the correct item

I am trying to create a chessboard. All coins are transparent, but the board is not. When I tried to get the clicked item using the "itemAt" function, it always returns the backGround element (which means the board). I suspect that due to the fact that the coins are transparent, they are not selected.

+4
source share
2 answers

I got an answer. I tried to get event->pos() . This will return the mouse click in the coordinates of QGraphicsItem . So I have to use event->scenePos() .

Now I get it right.

+2
source

If you use your own QGraphicsItem , you may need to override shape() ,

If this is a simple QGraphicsPixmapItem and it has an alpha mask, then you need to call setShapeMode() .

+1
source

Source: https://habr.com/ru/post/1313416/


All Articles