Results 1 to 6 of 6

Thread: How to add a picture to a Graphicsview

  1. #1
    Join Date
    Jul 2010
    Posts
    30
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to add a picture to a Graphicsview

    Hello
    My question today is:
    How to add a picture to a Graphicsview .
    I want to make it in the same size of Graphicsview.
    Or ,if possible, I want to make it zoom-able.

    Regards,

  2. The following user says thank you to Malek for this useful post:

    thaihoangluu (22nd December 2011)

  3. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to add a picture to a Graphicsview


  4. The following user says thank you to Lykurg for this useful post:

    thaihoangluu (22nd December 2011)

  5. #3
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: How to add a picture to a Graphicsview

    Or, you can instantiate a QGraphicsPixmapItem and give it to QGraphicsScene::addItem(). To be clear, you don't add anything to a QGraphicsView, which is nothing more than a "porthole", if you like, onto the QGraphicsScene, which contains all your pictures etc.

  6. The following user says thank you to Urthas for this useful post:

    thaihoangluu (22nd December 2011)

  7. #4
    Join Date
    Jul 2010
    Posts
    30
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to add a picture to a Graphicsview

    Thanks Lykurg .Thanks Urthas.

    My Partner has been found it.
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. QPixmap m("/home/MALEK/QT-Creator/PROJECTs/soso/bomb.jpeg");
    4. scene->setBackgroundBrush(m.scaled(100,100,Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
    5.  
    6. ui->graphicsView->setScene(scene);
    7. }
    To copy to clipboard, switch view to plain text mode 

    }

    But We still don't Know How to make it in the same size of white rectangle.And how to make it zoom-able.


    Thank you very much .
    Last edited by Malek; 22nd August 2010 at 00:23.

  8. The following user says thank you to Malek for this useful post:

    thaihoangluu (22nd December 2011)

  9. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to add a picture to a Graphicsview

    You can subclass QGraphicsView and in its paintEvent draw your picture scaled to the bounding rect.

  10. The following user says thank you to Lykurg for this useful post:

    thaihoangluu (22nd December 2011)

  11. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to add a picture to a Graphicsview

    Check the 40000 chips demo in Qt Demos.. you will get an idea how to zoom in / zoom out..

  12. The following user says thank you to aamer4yu for this useful post:

    thaihoangluu (22nd December 2011)

Similar Threads

  1. Qt Picture change
    By Raymond in forum Qt Programming
    Replies: 2
    Last Post: 22nd February 2010, 03:19
  2. Getting Chart as picture
    By codeman in forum Qt Programming
    Replies: 4
    Last Post: 24th November 2009, 12:39
  3. how to center picture in graphicsview?
    By lanmanck in forum Qt Programming
    Replies: 11
    Last Post: 28th August 2009, 07:09
  4. can't load picture
    By aoo7wangyan in forum Qt Programming
    Replies: 9
    Last Post: 13th July 2009, 14:59
  5. resize a picture
    By omega36 in forum Qt Programming
    Replies: 2
    Last Post: 9th January 2009, 14:34

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.