PDA

View Full Version : Setting areas of MainWindow that are click responsive



yonibr
1st April 2012, 12:05
I am working on a tic tac toe program. At the moment, I am trying to make it so that you can click where you want the "x" to go. I currently have an event handler for a mouse click:


void QWidget::mousePressEvent ( QMouseEvent *event )
{
QPoint mousePos = mapFromGlobal(QCursor::pos());
}


My goal now is to set up 9 different areas in the main window. I then want to determine which area received the click. What would these functions look like?
The 9 areas would fall in between the squares of the tic tac toe board. The function that draws that is here:



void MainWindow::paintEvent(QPaintEvent *event)
{
QPainter painter(this);

// Draw Tic Tac Toe Board
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, 10, Qt::SolidLine, Qt::RoundCap,
Qt::MiterJoin));
painter.drawLine(80, 20, 80, 250);

painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, 10, Qt::SolidLine, Qt::RoundCap,
Qt::MiterJoin));
painter.drawLine(170, 20, 170, 250);

painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, 10, Qt::SolidLine, Qt::RoundCap,
Qt::MiterJoin));
painter.drawLine(10, 90, 250, 90);

painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, 10, Qt::SolidLine, Qt::RoundCap,
Qt::MiterJoin));
painter.drawLine(10, 180, 250, 180);
}


Thanks for the help

wysota
1st April 2012, 15:03
There is a tic tac toe implementation available in Qt docs. Have a look at it.

yonibr
1st April 2012, 15:21
Thanks, but is there a way to do it without Qt Quick?
Edit: And I don't want the "x"s and "o"s to be buttons. I have the code to draw them done already. I just need code to draw them where the click happens.

wysota
1st April 2012, 15:25
The example I mean is not using Qt Quick.

Task Menu Extension

yonibr
1st April 2012, 15:27
can you post the link?

oops, just realized you did, sorry