I'd like to do something like this, even though I understand this is not how it works. I'm not really good with QMouseEvent,
void MainWindow::on_addState_triggered(QMouseEvent* event)
{
qDebug() << event->pos();
if (event->buttons() == Qt::LeftButton)
{
newBoard.drawState(event->x(),event->y());
}
}
So I want to click on the button addState in my interface (made with the Designer Mode, ui file) then on the second click on my scene it calls drawState() with the mouse (on click) position.
How I'm I supposed to do this ?
Right now the code compile but while running I get this error
QMetaObject::connectSlotsByName: No matching signal for on_addState_triggered(QMouseEvent*)
Alright, the way I imagine I can do it is a little bit ugly but it "works".
Maybe there is a cleaner way to do the following :
void MainWindow::on_addState_triggered()
{
drawAddState=true;
}
void MainWindow::mousePressEvent(QMouseEvent *event)
{
if(drawAddState==true)
{
if (event->button() == Qt::LeftButton) {
newBoard.drawState(event->localPos().x(),event->localPos().y());
drawAddState=false;
}
}
}
Unfortunately the event->localPos(), pos() or even GlobalPos is not relative to my GraphicsScene, I can't place the state item exactly where I click. Any idea on this ?
Update : I replied myself here : https://stackoverflow.com/a/62278962/13621190