Results 1 to 5 of 5

Thread: Display Images in QGraphicsView

  1. #1
    Join Date
    May 2007
    Location
    Ottawa, Canada
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Display Images in QGraphicsView

    I have placed a QGraphicsView widget on a main window and promoted it to
    a custom widget.

    I have created a scene attached to the view and added a pixmap to the scene.

    I then loaded a jpeg image into the scene.

    I copied the drawBackdrop method from the Qt Elastic Nodes sample.

    I get the backdrop drawn but can not see the loaded image.

    I've just started using designer - I can make this work coding by hand,
    but I seem to be missing something when trying to get the image to
    display when I do a show() on the top level main window generated by designer.

    anyone one have a bit of sample code that works that they could share - would be greatly appreciated.
    Rob Andrews (MIEEE)
    Principal Consultant - Andrews Consulting
    Resume at LinkedIn - <http://www.linkedin.com/in/robandrews>

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display Images in QGraphicsView

    Could you post the code sequence in question? Maybe you're doing something wrong there.

    Regards

  3. #3
    Join Date
    May 2007
    Location
    Ottawa, Canada
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display Images in QGraphicsView

    I have attached a compressed tar file with my attempt at getting an image
    into a graphicsviewer widget.

    thanks

    rob
    Attached Files Attached Files
    Rob Andrews (MIEEE)
    Principal Consultant - Andrews Consulting
    Resume at LinkedIn - <http://www.linkedin.com/in/robandrews>

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display Images in QGraphicsView

    Yes, I just tested with:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. QGraphicsScene *scn = new QGraphicsScene( w );
    5. scn->setSceneRect( w->rect() );
    6. w->setScene( scn );
    7. w->setFixedSize( 400, 400 );
    8. QPixmap pix( "c:\\pix_jpg.jpg" );
    9. scn->addPixmap( pix );
    10. w->show();
    11. a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 
    ( yes, this is a very poor example ).

    I loaded both your jpeg and some others, and also a png. All were OK.
    Maybe you have some problems with your jpeg plug-in. Try loading a png instead.

    Anyway, you should look at what pixmap.size() return after you load it.
    Regards
    Last edited by marcel; 15th May 2007 at 19:42.

  5. The following user says thank you to marcel for this useful post:

    robertaandrews (16th May 2007)

  6. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display Images in QGraphicsView

    Also ,make sure the path is correct.
    Last edited by marcel; 15th May 2007 at 19:42.

Similar Threads

  1. Is there any way to synchronize the display of images
    By kiransu123 in forum General Programming
    Replies: 2
    Last Post: 17th March 2007, 21:50
  2. Display multiple Images in a widget
    By jeetu_happy in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2007, 12:24
  3. Display animated images
    By suresh in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2007, 22:53
  4. How to display images in QTextBrowser ?
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2007, 09:58
  5. Widget to display images and text ?
    By probine in forum Qt Tools
    Replies: 4
    Last Post: 9th October 2006, 21:49

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.