开发者

qt - In QGraphicsScene I can't get the correct Item

开发者 https://www.devze.com 2023-01-04 09:54 出处:网络
I am trying to create a chessboard. All the coins are transparent and the board is not. When I tried to get the clicked item using the function \'itemAt\' it always returning the backGround item(that

I am trying to create a chessboard. All the coins are transparent and the board is not. When I tried to get the clicked item using the function 'itemAt' it always returning the backGround item(that means 开发者_运维技巧the board). I am suspecting that due to the fact that the coins are transparent, they are not selected.


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

Now I am getting it properly.


If you are using your own custom QGraphicsItem then you may need to override shape(),

If it's a plain QGraphicsPixmapItem and it has an alpha mask, then you need to call setShapeMode().

0

精彩评论

暂无评论...
验证码 换一张
取 消