qt - In QGraphicsScene how to catch a particular item -


There are many things in my QGraphicsScene I position I am creating a chess, and graphics view I am using So there are so many QGraphicsPixmapItems in QGraphicsScene . How can I get a king in this?

Update: In this QGraphicsScene , I QGraphicsPixmapItems which is adding nothing but coins (board, king, Queen, soldiers, etc.) Now if I want to take a particular coin, then the king, how can I get it? Here are some ways, like using an iterator. But there is no way to find its name with a particular QGraphicsPixmapItem .

When you say that you need to get a king, then you have a white king in your program and How do the differences between black color make?

If you have to meet a pawn, then how do you know who? Anyone ? Can you find in your items?

I have not thought much about it, but what you can do is using QMap. The key will be calculation of different pieces and the value will be an indicator for the relevant QGraphicsItem . Something like this:

  enum Piece_e {King, Queen, Rs 1, Roach 2, ... PAWN1, PAWN2, ...}; QMap & lt; Piece_e, QGraphicsPixmapItem * & gt; WhitePiecesItems; QMap & lt; Piece_e, QGraphicsPixmapItem * & gt; BlackPiecesItems;  

When you are making your own scene and instanciating your pieces, you will fill the map:

  ... whiteposts item [king ] = New QGraphicsPixmapItem (QPixmap ("whiteking_pic")); WhitePix item [PAWN1] = new QGraphicsPixmapItem (QPixmap ("whitepawn_pic")); ... black piece item [queen] = new qigraphics pixmap item (cupscams ("whitequine_pic")); Black piece item [PAWN1] = new QGraphicsPixmapItem (QPixmap ("whitepawn_pic")); ...  

When you have to find an item related to white king, you can do something like this:

  QGraphicsPixmapItem * pItem = WhitePiecesItem [King] ;  

Comments