PDA

View Full Version : Mouse Move event not functioning in Qscrollarea in tab widget



sandeep.theartist
11th July 2012, 04:38
Hi,

I Have a QScrollArea on my UI and ImageLabel inside QScrollarea.
I have successfully executed the code to scale the image with resize(pixmap) using Mainwindow::wheelEvent() and move the image within the QscrollArea with move(pixmap) using Mainwindow::mousePressEvent(),Mainwindow::mouseMov eEvent() and Mainwindow::mouseReleaseEvent().
When my UI contains the QScrollArea alone with imageLabel inside it, the program works fine.
But when I put QScrollArea inside a tabwidget, there are multiple issues.
1. Mainwindow::wheelEvent() works perfectly fine.
1. When I press left mouse button inside QScrollArea the controller does not enter into function Mainwindow::mousePressEvent()(Nothing happens) but when I press right mouse button, the controller enters into function Mainwindow::mousePressEvent().
2. The controller does not even enter into Mainwindow::mouseMoveEvent() function when I left/right click and drag the mouse inside QScrollArea.

What should I do on this??
Am I missing anything??

Qt Code:


void MainWindow::wheelEvent(QWheelEvent *myEvent)
{
int numDegree = myEvent->delta() / 8;
double numStep = numDegree / 15.0f ;
numStep = pow(0.9f,numStep);
scaleImage(numStep);
ui->imageLabel->setCursor(QCursor(Qt::ArrowCursor));
}

void MainWindow::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
lastDragPos = event->pos();
}

}

void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton)
{
lastDragPos = event->pos();
}

ui->imageLabel->move(pixmapOffset);


printf("MoveEvent-Pixmap offset x: %d and y: %d \n",pixmapOffset.x(),pixmapOffset.y());
ui->imageLabel->setCursor(QCursor(Qt::ClosedHandCursor));
}

void MainWindow::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{

pixmapOffset += event->pos() - lastDragPos;

}

ui->imageLabel->setCursor(QCursor(Qt::OpenHandCursor));

}

wysota
11th July 2012, 08:29
If you wish to handle an event in object X, you need to do that in implementation of object X, not its parent or grandparent.