Results 1 to 2 of 2

Thread: Mouse Move event not functioning in Qscrollarea in tab widget

  1. #1
    Join Date
    Jun 2012
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Mouse Move event not functioning in Qscrollarea in tab widget

    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:
    Qt Code:
    1. void MainWindow::wheelEvent(QWheelEvent *myEvent)
    2. {
    3. int numDegree = myEvent->delta() / 8;
    4. double numStep = numDegree / 15.0f ;
    5. numStep = pow(0.9f,numStep);
    6. scaleImage(numStep);
    7. ui->imageLabel->setCursor(QCursor(Qt::ArrowCursor));
    8. }
    9.  
    10. void MainWindow::mousePressEvent(QMouseEvent *event)
    11. {
    12. if (event->button() == Qt::LeftButton)
    13. {
    14. lastDragPos = event->pos();
    15. }
    16.  
    17. }
    18.  
    19. void MainWindow::mouseMoveEvent(QMouseEvent *event)
    20. {
    21. if (event->buttons() & Qt::LeftButton)
    22. {
    23. lastDragPos = event->pos();
    24. }
    25.  
    26. ui->imageLabel->move(pixmapOffset);
    27.  
    28.  
    29. printf("MoveEvent-Pixmap offset x: %d and y: %d \n",pixmapOffset.x(),pixmapOffset.y());
    30. ui->imageLabel->setCursor(QCursor(Qt::ClosedHandCursor));
    31. }
    32.  
    33. void MainWindow::mouseReleaseEvent(QMouseEvent *event)
    34. {
    35. if (event->button() == Qt::LeftButton)
    36. {
    37.  
    38. pixmapOffset += event->pos() - lastDragPos;
    39.  
    40. }
    41.  
    42. ui->imageLabel->setCursor(QCursor(Qt::OpenHandCursor));
    43.  
    44. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Mouse Move event not functioning in Qscrollarea in tab widget

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Problem with QGraphicsScene mouse move event
    By Nesbit in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2012, 18:12
  2. Replies: 3
    Last Post: 7th January 2012, 08:38
  3. QAbstractItemView not calling mouse move event function
    By sagirahmed in forum Qt Programming
    Replies: 0
    Last Post: 5th July 2010, 10:26
  4. mouse move event filtering in PyQt4
    By lucaf in forum Qt Programming
    Replies: 1
    Last Post: 4th April 2009, 14:53
  5. Mouse Move Event
    By merry in forum Newbie
    Replies: 5
    Last Post: 3rd June 2007, 06:26

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.