Results 1 to 4 of 4

Thread: Facing problem with Q3Canvas

  1. #1
    Join Date
    Feb 2006
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Facing problem with Q3Canvas

    Hi All,

    I want to zoom in a region on canvas. For that first I am drawing a rectangle on canvas, size of the rectangle is decided by mouse move event. Then zooming in the mouse movement area to full region. The problem is view of the canvas rectangle which I am drawing to show the selected region.If the region is from initial view port area then the the rectangle is visible. The problem is, by moving scroll bar if mouse is in different viewport region, then it is not showing the whole rectangle area. It is only showing the rectangle area which is in initial view port(scroll bar at zero position). However zooming in is done properly.

    I am attaching the code part also. Please rectify my mistake.

    Thanks
    Jnana

    Qt Code:
    1. void
    2. DiagramView :: contentsMouseMoveEvent(QMouseEvent* a_e)
    3. {
    4. if(cursor().shape() == Qt::CrossCursor) {
    5. //QPoint myPoint = viewportToContents(a_e->pos());
    6. m_zoomEndPoint = (inverseWorldMatrix()).map(a_e->pos());
    7. int width = m_zoomEndPoint.x()-m_zoomStartPoint.x();
    8. int height = m_zoomEndPoint.y()-m_zoomStartPoint.y();
    9. if((width>0)&&(height>0)) {
    10. if(!m_zoomRegionRect) {
    11. qDebug(QString("%1 %2").arg(width).arg(height));
    12. //! canvas item do not exist
    13. m_zoomRegionRect = new Q3CanvasRectangle(m_zoomStartPoint.x(),
    14. m_zoomStartPoint.y(),
    15. width, height, canvas());
    16. m_zoomRegionRect->setBrush(Qt::DiagCrossPattern);
    17. m_zoomRegionRect->setPen(QPen(Qt::darkGreen,
    18. 2, Qt::DashDotDotLine));
    19. m_zoomRegionRect->setZ(100);
    20. m_zoomRegionRect->show();
    21. } else {
    22. m_zoomRegionRect->setSize(width, height);
    23. canvas()->setChanged(m_zoomRegionRect->boundingRect());
    24. }
    25. canvas()->update();
    26. }
    27. return;
    28. }
    29. }
    30. void
    31. DiagramView :: contentsMousePressEvent(QMouseEvent* a_e)
    32. {
    33. m_zoomStartPoint = (inverseWorldMatrix()).map(a_e->pos());
    34. }
    35.  
    36. void
    37. DiagramView :: contentsMouseReleaseEvent(QMouseEvent* )
    38. {
    39. if(cursor().shape() == Qt::CrossCursor) {
    40. if(m_zoomRegionRect) {
    41. m_zoomRegionRect->hide();
    42. canvas()->update();
    43. delete m_zoomRegionRect;
    44. m_zoomRegionRect = 0;
    45. m_zoomStartFlag = true;
    46. emit ZoomToRegion(m_zoomStartPoint, m_zoomEndPoint);
    47. canvas()->update();
    48. }
    49. return;
    50. }
    51. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Facing problem with Q3Canvas

    You should map the scrollarea's coordinates to the viewport coordinates either by adding values of the scrollbars or by using mapFromParent.

    Qt Code:
    1. m_zoomStartPoint = (inverseWorldMatrix()).map(mapFromParent(a_e->pos()));
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2006
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Facing problem with Q3Canvas

    Hi ,

    Still it is not working.

    Qt Code:
    1. void
    2. DiagramView :: contentsMouseMoveEvent(QMouseEvent* a_e)
    3. {
    4. if(cursor().shape() == Qt::CrossCursor) {
    5. //QPoint myPoint = viewportToContents(a_e->pos());
    6. m_zoomEndPoint = (inverseWorldMatrix()).map(mapFromParent(a_e->pos()));
    7. int width = m_zoomEndPoint.x()-m_zoomStartPoint.x();
    8. int height = m_zoomEndPoint.y()-m_zoomStartPoint.y();
    9. if((width>0)&&(height>0)) {
    10. if(!m_zoomRegionRect) {
    11. //! canvas item do not exist
    12. m_zoomRegionRect = new Q3CanvasRectangle(m_zoomStartPoint.x(),
    13. m_zoomStartPoint.y(),
    14. width, height, canvas());
    15. m_zoomRegionRect->setBrush(Qt::DiagCrossPattern);
    16. m_zoomRegionRect->setPen(QPen(Qt::darkGreen,
    17. 2, Qt::DashDotDotLine));
    18. m_zoomRegionRect->setZ(100);
    19. m_zoomRegionRect->show();
    20. } else {
    21. m_zoomRegionRect->setSize(width, height);
    22. canvas()->setChanged(m_zoomRegionRect->boundingRect());
    23. }
    24. canvas()->update();
    25. }
    26. return;
    27. }
    28. }
    29. void
    30. DiagramView :: contentsMousePressEvent(QMouseEvent* a_e)
    31. {
    32. m_zoomStartPoint = (inverseWorldMatrix()).map(mapFromParent(a_e->pos()));
    33. }
    34.  
    35. void
    36. DiagramView :: contentsMouseReleaseEvent(QMouseEvent* )
    37. {
    38. if(cursor().shape() == Qt::CrossCursor) {
    39. if(m_zoomRegionRect) {
    40. m_zoomRegionRect->hide();
    41. canvas()->update();
    42. delete m_zoomRegionRect;
    43. m_zoomRegionRect = 0;
    44. m_zoomStartFlag = true;
    45. emit ZoomToRegion(m_zoomStartPoint, m_zoomEndPoint);
    46. canvas()->update();
    47. }
    48. return;
    49. }
    50. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Facing problem with Q3Canvas

    hi.

    are u deriving the class DiagramView from Q3CanvasView...

    For me something like this works pretty fine...

    Qt Code:
    1. void CanvasMouse::contentsMousePressEvent(QMouseEvent* e)
    2. {
    3. if(e->button() == Qt::LeftButton)
    4. {
    5. QPoint pPress = inverseWorldMatrix().map(e->pos());
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    though it seems a crude method but try something like this that try to call the mouse events in the class where u have created the canvas... where u have set its size and its view... it might help...

    Kapil
    All you have to decide is what to do with the time that is given to you

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  2. Replies: 3
    Last Post: 2nd July 2008, 03:00
  3. i am facing a problem with QTextEdit!!!
    By mismael85 in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2008, 18:06
  4. Facing problem with tool bar icons
    By jnana in forum Qt Programming
    Replies: 4
    Last Post: 20th April 2006, 08:37
  5. Facing problem with qt-4.1 designer
    By jnana in forum Qt Tools
    Replies: 4
    Last Post: 8th March 2006, 18:16

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.