Results 1 to 2 of 2

Thread: Left align the items on Zommout

  1. #1
    Join Date
    Nov 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Left align the items on Zommout

    When doing zoomIn, zoom happens on left aligned (item on top left is always visible) but on zoom out items going to the center of the view by leaving lot of space on left,

    I want all items should be left aligned on zoom out also.

    Code for LeftAigned ZoomIn.
    Qt Code:
    1. void csGuiView::wheelEvent(QWheelEvent *event)
    2. {
    3.  
    4. if ((event->modifiers()&Qt::ControlModifier) == Qt::ControlModifier
    5. && event->angleDelta().x() == 0)
    6. {
    7. QPoint pos = event->pos();
    8. QPointF posf = this->mapToScene(pos);
    9.  
    10. double angle = event->angleDelta().y();
    11.  
    12. double scalingFactor;
    13.  
    14. if(angle > 0)
    15. {
    16. scalingFactor = 1 + ( angle / 360 * 0.1);
    17. }else if (angle < 0)
    18. {
    19. scalingFactor = 1 - ( -angle / 360 * 0.1);
    20. } else
    21. {
    22. scalingFactor = 1;
    23. }
    24.  
    25. m_pvtData->m_scale = scalingFactor;
    26.  
    27. this->scale(scalingFactor, scalingFactor);
    28.  
    29. double w = this->viewport()->width();
    30. double h = this->viewport()->height();
    31.  
    32. double wf = this->mapToScene(QPoint(w-1, 0)).x()
    33. - this->mapToScene(QPoint(0,0)).x();
    34. double hf = this->mapToScene(QPoint(0, h-1)).y()
    35. - this->mapToScene(QPoint(0,0)).y();
    36.  
    37. double lf = posf.x() - pos.x() * wf / w;
    38. double tf = posf.y() - pos.y() * hf / h;
    39.  
    40. /* try to set viewport properly */
    41. this->ensureVisible(lf, tf, wf, hf);
    42.  
    43.  
    44. QPointF newPos = this->mapToScene(pos);
    45.  
    46.  
    47. this->ensureVisible(QRectF(QPointF(lf, tf) - newPos + posf,
    48. QSizeF(wf, hf)), 0, 0);
    49.  
    50. }
    51.  
    52. if ((event->modifiers()&Qt::ControlModifier) != Qt::ControlModifier) {
    53. QGraphicsView::wheelEvent(event);
    54. }
    55.  
    56. event->accept();
    57. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Last edited by high_flyer; 8th December 2017 at 22:46. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Left align the items on Zommout

    I am not sure about this (years since I have done anything with QGraphicsView - but I'd try setting the view alignment to top left:
    http://doc.qt.io/qt-5/qgraphicsview.html#alignment-prop

    If this does not help, I'd experiment with the viewport anchor:
    http://doc.qt.io/qt-5/qgraphicsview....ionAnchor-prop

    Please share here if you have solved it and how.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 6
    Last Post: 16th April 2013, 16:13
  2. Replies: 1
    Last Post: 10th March 2013, 17:40
  3. Replies: 0
    Last Post: 6th November 2009, 21:59
  4. how align some buttons in QToolbar from right to left?
    By davi_all4one in forum Qt Programming
    Replies: 3
    Last Post: 7th September 2009, 11:15
  5. How to align list items to the center?
    By zgulser in forum Qt Tools
    Replies: 4
    Last Post: 9th February 2009, 09:52

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.