Hello. I'm a begginer, then please don't scream at me
I'm having problems with my simple application. mousePressEvent works fine (even in QgraphisView), but mouseRelaseEvent doesn't work in one. Please help. I'm using QT 4.4.3
This is part of my code:
{
(...)
image1->setFixedSize(200, 120);
image1->setMouseTracking(true);
image1->setInteractive (true);
image1->setAcceptDrops(true);
(...)
image1->setScene(area1);
image1->show();
(...)
// x & y drag's position
// width & height drag's position
(...)
}
(...)
{
QPoint pozycja
= event
->pos
();
QPoint posSceny
= BlackCat
::image1->mapFromScene
(pozycja
);
int posx = posSceny.x();
int posy = posSceny.y();
num1.setNum(posx);
num2.setNum(posy);
this->selectedx->setText(num1);
this->selectedy->setText(num2);
}
{
QPoint pozycja
= event
->pos
();
QPoint posSceny
= BlackCat
::image1->mapFromScene
(pozycja
);
int posx = pozycja.x();
int posy = pozycja.y();
num1.setNum(posx);
num2.setNum(posy);
this->selectedw->setText(num1);
this->selectedh->setText(num2);
}
BlackCat::BlackCat(QWidget *parent) : QWidget (parent)
{
(...)
area1 = new QGraphicsScene;
image1 = new QGraphicsView;
image1->setFixedSize(200, 120);
image1->setMouseTracking(true);
image1->setInteractive (true);
image1->setAcceptDrops(true);
image1->setDragMode(QGraphicsView::NoDrag);
(...)
image1->setScene(area1);
image1->show();
(...)
// x & y drag's position
selectedx = new QLineEdit();
selectedy = new QLineEdit();
// width & height drag's position
selectedw = new QLineEdit();
selectedh = new QLineEdit();
(...)
}
(...)
void BlackCat::mousePressEvent(QMouseEvent *event)
{
QPoint pozycja = event->pos();
QPoint posSceny = BlackCat::image1->mapFromScene(pozycja);
int posx = posSceny.x();
int posy = posSceny.y();
QString num1, num2;
num1.setNum(posx);
num2.setNum(posy);
this->selectedx->setText(num1);
this->selectedy->setText(num2);
}
void BlackCat::mouseReleaseEvent(QMouseEvent *event)
{
QPoint pozycja = event->pos();
QPoint posSceny = BlackCat::image1->mapFromScene(pozycja);
int posx = pozycja.x();
int posy = pozycja.y();
QString num1, num2;
num1.setNum(posx);
num2.setNum(posy);
this->selectedw->setText(num1);
this->selectedh->setText(num2);
}
To copy to clipboard, switch view to plain text mode
Bookmarks