Results 1 to 5 of 5

Thread: unable to translate QGraphicsView

  1. #1
    Join Date
    May 2009
    Location
    Germany
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default unable to translate QGraphicsView

    hi,

    do I have to set a flag or anything else if I want to use QGraphicsView->translate()
    or why is it not working for me although rotate, scale and shear are working well.
    I also tried with QTransform and QMatrix, but I got the same result:
    on setTransform and setMatrix only rotate, scale and shear are visible.
    I tried different SceneRectangles as well and dont know what else to try...

    thanks a lot
    sven

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: unable to translate QGraphicsView

    yes the same thing i am trying for QTransform to rotate the view but no vain ..

    in Qt demo chip application

    they use QMatrix only to rotate the QGraphicsView()

    see in chip/view.cpp
    Qt Code:
    1. void View::setupMatrix()
    2. {
    3. qreal scale = qPow(qreal(2), (zoomSlider->value() - 250) / qreal(50));
    4.  
    5. QMatrix matrix;
    6. matrix.scale(scale, scale);
    7. matrix.rotate(rotateSlider->value());
    8.  
    9. graphicsView->setMatrix(matrix);
    10. setResetButtonEnabled();
    11. }
    To copy to clipboard, switch view to plain text mode 

    i dont know why they dont use QTransform
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Aug 2009
    Location
    Atlanta, GA
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: unable to translate QGraphicsView

    sven,

    I also tried using translate() and QMatrix but what finally worked was setting the two scrollbars' value; this works even if the scrollbars are turned off:


    Qt Code:
    1. QScrollBar* myVScrollbar;
    2. myVScrollbar = myView->verticalScrollBar();
    3. myVScrollbar->setValue(myVScrollbar->value() + offsetValue);
    4.  
    5. QScrollBar* myHScrollbar;
    6. myHScrollbar = myView->horizontalScrollBar();
    7. myHScrollbar->setValue(myHScrollbar->value() + offsetValue);
    To copy to clipboard, switch view to plain text mode 

    And subtract offsetValue to move in the opposite direction.

  4. #4
    Join Date
    May 2009
    Location
    Germany
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: unable to translate QGraphicsView

    thanks,

    moving the scrollbars works, but it doesnt look very precisely as well..

  5. #5
    Join Date
    Nov 2008
    Posts
    6
    Thanks
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: unable to translate QGraphicsView

    Thank you so much for your tip !

    I had the same problem, i.e. QGraphicsView::translate() not working well.
    In my case, I had to call it several times to observe a change... ? I tried different SceneRect() as well.

    Moving the scrollbars works perfectly for me.
    Thanks again

Similar Threads

  1. Replies: 0
    Last Post: 5th March 2009, 06:54
  2. Replies: 2
    Last Post: 26th February 2009, 10:12
  3. QGraphicsView and embeded widgets
    By bunjee in forum Qt Programming
    Replies: 10
    Last Post: 12th October 2008, 07:43
  4. How to Compile VTKDesigner2 with Qt?
    By alfredoaal in forum Newbie
    Replies: 0
    Last Post: 5th September 2008, 05:34
  5. Speed, transparency, and drop issues with QGraphicsView
    By jefferai in forum Qt Programming
    Replies: 16
    Last Post: 30th June 2007, 16:14

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.