Results 1 to 5 of 5

Thread: Cannot open gif in Graphics View

  1. #1
    Join Date
    Dec 2012
    Posts
    17
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default Cannot open gif in Graphics View

    I am designing a page which has Graphics View widget. I intend to run a gif in it. I have looked into various documentation and tried running the following code, but i am not getting the result, Please help.

    1.Mainwindow.cpp :

    Qt Code:
    1. ui(new Ui::MainWindow)
    2. {
    3. ui->setupUi(this);
    4. scene = new QGraphicsScene(this);
    5. ui->graphicsView->setScene(scene);
    6. QLabel *gif_anim = new QLabel();
    7. QMovie *movie = new QMovie("Sin_drawing_process.gif");
    8. gif_anim->setMovie(movie);
    9. movie->start();
    10. proxy = scene->addWidget(gif_anim);
    11.  
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 



    2.Mainwindow.h
    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. private:
    4. Ui::MainWindow *ui;
    5. QGraphicsProxyWidget *proxy;
    6. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Cannot open gif in Graphics View

    What result are you not getting? No proxy widget, no image, no animation?

    This code showing an endless gif animation, for example, runs fine here:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv)
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QGraphicsScene *scene = new QGraphicsScene(&view);
    8. view.setScene(scene);
    9. QLabel *gif_anim = new QLabel();
    10. QMovie *movie = new QMovie("dna_e0.gif");
    11. gif_anim->setMovie(movie);
    12. movie->start();
    13. QGraphicsProxyWidget *proxy = scene->addWidget(gif_anim);
    14. view.show();
    15.  
    16. return app.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to ChrisW67 for this useful post:

    alok9871 (28th December 2012)

  4. #3
    Join Date
    Dec 2012
    Posts
    17
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default Re: Cannot open gif in Graphics View

    Hi ChrisW67

    Thanks for your reply. Gives me a hint, I am near-about.

    Unfortunately, I could not even import an image on to the widget.

    Well I tried to draw something inside the graphicsView, I could do it. But importing an image or a gif is something that i haven't been able to achieve. To my code, I changed the background color of the Graphics View, What I found was that at the centre there is a small white rectangle.

    Any suggestions on where I have gone wrong?


    Added after 35 minutes:


    I ran your code, and I get this as output.

    animationtry.png
    Last edited by alok9871; 28th December 2012 at 08:57.

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Cannot open gif in Graphics View

    You have one of these two problems:
    • The image is not in the location you are trying to load it from.
    • You do not have a GIF image format plugin or you have deployed the program to another computer and not deployed the plugin.


    My money is on the first.

    The code I gave you depends on having the image file (dna_e0.gif) in the current working directory of the running program. Please note that this is not generally the same as the directory containing the executable or the source code directory. If you are running the program inside Qt Creator with shadow building turned on (the default) the the run-time current working directory is definitely not the source directory, which is most likely where you put the gif file.

    You can use QCoreApplication::applicationDirPath () to locate an image relative to the executable directory.
    You can use the Qt resource system to embed the image in your executable.

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

    alok9871 (31st December 2012)

  7. #5
    Join Date
    Dec 2012
    Posts
    17
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default Re: Cannot open gif in Graphics View

    Thank you ChrisW67. You are not called Guru for no reason!

    I created a Qt Resource file(.qrc) . I put my gif file in the folder--> Right-clicked on the file to copy the resource file path-> pasted it on to the QMovie field--> got the result.

    Many thanks

Similar Threads

  1. Graphics/View + dialogs
    By AeroB in forum Qt Programming
    Replies: 2
    Last Post: 19th June 2012, 14:39
  2. Graphics View : too many lines
    By natnan in forum Qt Programming
    Replies: 6
    Last Post: 28th January 2010, 11:15
  3. Graphics View and the Pixmap
    By spawn9997 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2009, 22:12
  4. graphics view painting
    By dognzhe in forum Qt Programming
    Replies: 3
    Last Post: 12th May 2009, 07:26
  5. Graphics View or Paint ?
    By igor in forum Qt Programming
    Replies: 4
    Last Post: 21st January 2007, 13:21

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
  •  
Qt is a trademark of The Qt Company.