Qt Forum

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

    Solved QGraphicsView: How to calculate the center?

    General and Desktop
    2
    2
    1994
    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.
    • X
      xtingray last edited by xtingray

      Hi,
      I am looking for the best way to calculate the current center of a QGraphicsView instance. The way to set the center is very easy using the centerOn() method, but if I want to get the opposite action (to get the QPoint center value), how should I do it?

      Thank you for any hint :)


      Qt Developer

      1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by raven-worx

        QRectF rect = view->scene()->sceneRect();
        QPointF center = rect.center();
        

        or do you mean the center on which the scene is currently scrolled?

        QPointF sceneCenter = view->mapToScene( view->viewport()->rect().center() );
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

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