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. Put an item on the QGraphicsView
Forum Updated to NodeBB v4.3 + New Features

Put an item on the QGraphicsView

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.0k 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.
  • B Offline
    B Offline
    browser90
    wrote on last edited by
    #1

    Hi,

    I've created via the designer a form with a qgraphicsview in it. Now in my constructor of the mainwindow I would like to place a image in the view, but nothing works. I thought I could do it with ui->nameofview->addPixmapItem but I can't?

    It's the first time it do this via the designer so what is wrong with?

    In my previous project I did it without the creator with this code:

    @
    item = new QGraphicsPixmapItem( QPixmap::fromImage(worldImage));
    this->addItem(item);
    @

    but this doens't work :s

    Kind regards,

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

      Is the image linked well? I've seen a lot of threads where the filepaths aren't formed well.

      File not found. Nobody leave the room!

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        Hi,
        You need to add a scene to your graphics view and then add the QGraphicsPixmapItem to the scene
        e.g

        @scene = new QGraphicsScene(this);
        ui->graphicsView->setScene(scene);

        QImage worldImage("your image path");
        item = scene->addPixmap(QPixmap::fromImage(worldImage));@

        Where item is QGraphicsPixmapItem and scene is QGraphicsScene.

        Try If this works.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          browser90
          wrote on last edited by
          #4

          Jup forgot this because of the creator :-) thanks.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sam
            wrote on last edited by
            #5

            Yes this is very common mistake, even i got confused initially when using the graphicsView. Kindly Edit your first Post and mark it [SOLVED],

            Happy Coding !!!!

            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