Results 1 to 2 of 2

Thread: Left align the items on Zommout

Threaded View

Previous Post Previous Post   Next Post Next Post
  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 23:46. Reason: missing [code] tags

Similar Threads

  1. Replies: 6
    Last Post: 16th April 2013, 17:13
  2. Replies: 1
    Last Post: 10th March 2013, 18:40
  3. Replies: 0
    Last Post: 6th November 2009, 22: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, 12:15
  5. How to align list items to the center?
    By zgulser in forum Qt Tools
    Replies: 4
    Last Post: 9th February 2009, 10: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.