Results 1 to 5 of 5

Thread: loading an image onto any form's widget

  1. #1
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default loading an image onto any form's widget

    hi friends, i can able to load a text file onto the form's "textEdit" widget but i am not able to load an image since in a Designer there are only few display widget(like QGraphicsView,LCD) so how can i load an image????

  2. #2
    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: loading an image onto any form's widget

    With QTextEdit you will have to use QTextDocument::addResource():
    Qt Code:
    1. textEdit->document()->addResource(QTextDocument::ImageResource, QUrl("url-used-in-html"), QImage("image.png"));
    To copy to clipboard, switch view to plain text mode 
    Just notice that QTextBrowser is capable of loading resources from local files out of the box.
    J-P Nurmi

  3. #3
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Post Re: loading an image onto any form's widget

    not only with the QTextEdit, but there are other classes like QImage,QImageReader how can i use these classes to display the image. I have written something like this

    "QString filename = QFileDialog::getOpenFileName(this);"

    with this file "filename" can i display the image using QImage class (since it has fun'
    QImage::QImage ( const QString & fileName, const char * format = 0 ) )

    any suggess' plz welcome

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: loading an image onto any form's widget

    If you just want to display an image, you can use QLabel. Also use QPixmap instead of QImage.

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

    sudheer (1st December 2007)

  6. #5
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Post Re: loading an image onto any form's widget

    thank q , now i can able to display system image files(.jpg,.png,gif,.bmp format ) using
    both classes QLabel(on form's label widget) and QPixmap

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. Background image and semitransparent widget
    By asieriko in forum Qt Programming
    Replies: 3
    Last Post: 20th August 2007, 16:43
  3. QTextEdit and delayed image loading
    By Vladimir in forum Qt Programming
    Replies: 5
    Last Post: 27th April 2007, 08:13
  4. Loading a custom image into a QPixmap
    By KShots in forum Qt Programming
    Replies: 12
    Last Post: 5th August 2006, 00:16
  5. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36

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.