Results 1 to 5 of 5

Thread: diplaying image

  1. #1
    Join Date
    Mar 2008
    Location
    Morocco
    Posts
    47
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default diplaying image

    Hey..
    I m new begginer in Qt .. I had a problem to display a simple image on a graphicsView ..
    I tried the following instruction :


    Qt Code:
    1. QPixmap image(path);
    2. myview->setBackgroundBrush(image); //myview is a graphicsView Class
    To copy to clipboard, switch view to plain text mode 

    But Nothing Appear .. Actually I had a trouble with Using GraphicsView .. there is many class (GraphicsScene .. GrphicItem ... ) But I really Dont Know Wht To USe ..

    Plzzz If Some Could Help Me On ThaT!!!!!!!!
    Last edited by jpn; 1st April 2008 at 16:56. Reason: missing [code] tags

  2. #2
    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: diplaying image

    do u want to display image on graphics view only ??
    U can use QLabel too. Check the image viewer example in Qt Demo

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: diplaying image

    Quote Originally Posted by peace_comp View Post
    But I really Dont Know Wht To USe ..

    Plzzz If Some Could Help Me On ThaT!!!!!!!!
    I'm afraid this won't encourage people to help you...

    Anyway, what does
    Qt Code:
    1. #include <QtDebug>
    2. #include <QImageReader>
    3.  
    4. // after constructing the image
    5. qDebug() << path << image.isNull() << QImageReader::supportedFormats();
    To copy to clipboard, switch view to plain text mode 
    output?
    J-P Nurmi

  4. #4
    Join Date
    Mar 2008
    Location
    Morocco
    Posts
    47
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: displaying image

    qDebug() << path << image.isNull() << QImageReader::supportedFormats();

    Error: supportedFormats() is not a memeber of QImageReader...

    well .. actualy I read Some Tuto About Graphics ...What I understand is That a QGraphicsScene sereves as a container for QgraphicsItem ..and The QGraphicsView Provides the View Widget that Visualize the contain of scene..
    So I tryed That Code :

    Qt Code:
    1. //connect (actionOpen,SIGNAL(triggered()),this,SLOT(Open()));
    2.  
    3. void myform::Open(){
    4.  
    5. path=QFileDialog::getOpenFileName(this,"Choose a file to oepn",QString::null,QString::null);
    6.  
    7. if(!path.isEmpty()){
    8. QPixmap image(path);
    9. QGraphicsPixmapItem mypixmap(image);
    10. scene->addItem(&mypixmap); //scene declared as QGraphicsScene
    11. graphicsView->setScene(scene); //graphicsView as QGraphicsView
    12. graphicsView->show();
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    but Nothing was displayed on the graphicsView ... (but a scrollbar was added to the View)
    Sould I refresh My graphicsView or did I miss some function for displayin;??

    Thanks for Help
    Last edited by jpn; 2nd April 2008 at 12:23. Reason: missing [code] tags

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: displaying image

    Quote Originally Posted by peace_comp View Post
    qDebug() << path << image.isNull() << QImageReader::supportedFormats();

    Error: supportedFormats() is not a memeber of QImageReader...
    Sorry for the typo. It should be "supportedImageFormats". But you know, you could just have looked up in QImageReader docs what's the correct name of the function... Takes less time than posting here.

    Anyway, the problem seems to be that you allocate the item on the stack. It goes out of scope and gets automatically destructed according to normal C++ rules. You should allocate it on the heap instead of you want it to remain alive.
    J-P Nurmi

Similar Threads

  1. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  2. Help needed handling image data
    By toratora in forum General Programming
    Replies: 2
    Last Post: 11th May 2007, 09:24
  3. how i can add image in my toolbar
    By jyoti in forum Qt Tools
    Replies: 7
    Last Post: 19th December 2006, 14:39
  4. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36
  5. Question about updating an image on screen
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 19:01

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.