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/QGraphicsScene
Forum Updated to NodeBB v4.3 + New Features

QGraphicsView/QGraphicsScene

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 5.1k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    cazador7907
    wrote on last edited by
    #1

    I just started learning how to display images to the User. In reading through the documentation it seems that the QGraphicsView and QGraphicsScene offer the best approach. Basically, I want to a display a map to the User in the main Window and then overlay dialog boxes containing controls and/or other information to the user.

    In my first attempt to display the base image to the User it was displayed in repeating panels. I just want to display a single image centered on the screen. I've been reading through the documentation but so far haven't discovered how to center the image in the view.

    @
    QGraphicsScene scene;
    scene.setSceneRect(-300, -300, 600, 600);
    scene.setItemIndexMethod(QGraphicsScene::NoIndex);

    QGraphicsView view(&scene);
    view.setRenderHint(QPainter::Antialiasing);
    view.setBackgroundBrush(QPixmap(":/Game/DataFiles/map.jpg"));
    view.setCacheMode(QGraphicsView::CacheBackground);
    view.setAlignment(Qt::AlignCenter);
    view.setContentsMargins(QMargins::QMargins(5, 5, 5, 5));
    view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Map Test"));
    view.resize(900, 700);
    view.show();
    

    @

    Laurence -

    1 Reply Last reply
    0
    • W Offline
      W Offline
      w00t
      wrote on last edited by
      #2

      If you want a single image, AFAIK, you'll need to use QGraphicsItem (or QGraphicsWidget). Setting the image as a background brush will, as you've observed, result in it being tiled, because it is painted across the entirety of the background.

      --
      http://rburchell.com

      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