Ok, so you probably you have some methods like
void selectSquare1();
void selectSquare2();
//...
void selectSquare1();
void selectSquare2();
//...
To copy to clipboard, switch view to plain text mode
Then just use mousePressEvent method to get clicked position and determine which square was clicked:
void MyWidgetClass
::mousePressEvent( QMouseEvent * event
){ const QPoint pos
= event
->pos
();
qDebug() << "clicked pos : " << pos;
// calculate index of square using pos coordinates
int index = getSquareIndex(pos);
this->selectSquare( index );
}
void MyWidgetClass::mousePressEvent( QMouseEvent * event ){
const QPoint pos = event->pos();
qDebug() << "clicked pos : " << pos;
// calculate index of square using pos coordinates
int index = getSquareIndex(pos);
this->selectSquare( index );
QMainWindow::mousePressEvent(event);
}
To copy to clipboard, switch view to plain text mode
Too bad your game is almost finished, because using the Qt graphics view framework is more suitable for this kind of 2d graphics programming ( for example, if you want to add possibility of interaction with rendered items ).
Bookmarks