Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QGrahicsView "translate" has no effect

    General and Desktop
    3
    3
    931
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      Linux777 last edited by

      Hello!
      I have my custom class derived from QGrahicsView.

      void my_view::wheelEvent(QWheelEvent *event)
      {
      	QTransform tf;
      	tf.translate(offset.x(), offset.y());
      	tf.scale(current_scale, current_scale);
      	tf.rotate(r);
      	setTransform(tf, false);
      }
      

      Scale - working, rotate - excellent, translate - absolutely no effect! but offset.x/y is changing.

      I tried many many things such as:

      • setAlignment(0);
      • setTransformationAnchor(QGraphicsView::NoAnchor); + setResizeAnchor(QGraphicsView::NoAnchor);
      • centerOn(event->pos());

      I just want to view different parts of my scene more detailed with higher zoom. Please help me, I'm so much confused and angry that dumb primitive action just move view is not working at all... =(

      Which highly intelligent options of QGraphicView I should turn off to make this thing just do what I want without any implicit impacts on my "orders"?

      1 Reply Last reply Reply Quote 0
      • A
        Asperamanca last edited by

        My first idea is that the scene is too small. Do you have scrollbars, and if so, can you navigate using them?

        Other things to try: fitInView, ensureVisible

        1 Reply Last reply Reply Quote 0
        • ?
          A Former User last edited by A Former User

          The scene is automatically translated according to the view's alignment settings. This is done so that the scrollbars work as expected in most use cases. To achieve what you want the easiest way is to set alignment to AlignLeft and AlignTop, make the sceneRect the same size as the view and then don't apply translations to the view but to the sceneRect (= increase / decrease the x and y of the sceneRect). And always disable the scrollbars.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post