Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsView: How to calculate the center?

QGraphicsView: How to calculate the center?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 2.6k Views
  • 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 Offline
    X Offline
    xtingray
    wrote on last edited by xtingray
    #1

    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
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2
      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved