Results 1 to 8 of 8

Thread: Inserting Image into a QTextBox

  1. #1
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question Inserting Image into a QTextBox

    Dear Everyone!
    How a way we can insert image into a QTextBox.
    regards!
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  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: Inserting Image into a QTextBox

    I suppose you mean QTextEdit? Which version of Qt are we talking about? Qt 3 and Qt 4 are pretty much different so could you please mark your questions related to either one.
    J-P Nurmi

  3. #3
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Exclamation Re: Inserting Image into a QTextEdit

    I use Qt3 for this.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  4. #4
    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: Inserting Image into a QTextBox

    From QTextEdit docs:
    QTextEdit can display images (using QMimeSourceFactory), lists and tables.
    ...
    The images identified by image tags are displayed if they can be interpreted using the text edit's QMimeSourceFactory; see setMimeSourceFactory().
    What did you try so far?
    J-P Nurmi

  5. #5
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question Re: Inserting Image into a QTextBox

    Quote Originally Posted by jpn View Post
    From QTextEdit docs:

    What did you try so far?
    I want to insert .png image into QTextEdit. Plz give me a example to insert this using Qt3 as well as Qt4.
    Thanks in advance!
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  6. #6
    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: Inserting Image into a QTextBox

    Don't you think it would be appropriate to show some effort on your own?

    Last edited by jpn; 15th September 2007 at 09:32. Reason: reformatted to look better
    J-P Nurmi

  7. #7
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question Re: Inserting Image into a QTextBox

    Quote Originally Posted by jpn View Post
    Don't you think it would be appropriate to show some effort on your own?

    Dear Sir i am using following code. it run but doesn't show image into QTextEdit.
    #include <qpixmap.h>
    #include <qmime.h>

    void dlgImage:bShowImage_clicked()
    {
    QPixmap pImg("s.png",0,1);
    QMimeSourceFactory *factory=new QMimeSourceFactory();
    factory->setPixmap("/root/desktop/img/s.png",pImg); /* I cann't understand the first argument means*/
    txtImage->setMimeSourceFactory(factory);

    }
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  8. #8
    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: Inserting Image into a QTextBox

    Quote Originally Posted by ashukla View Post
    I cann't understand the first argument means
    This is explained in the detailed description of QMimeSourceFactory. It should equal the source-attribute of image-element:
    Qt Code:
    1. QMimeSourceFactory::defaultFactory()->setPixmap("anything_you_want", pImg);
    2. textEdit->setHtml("<img source=\"anything_you_want\">");
    To copy to clipboard, switch view to plain text mode 

    Edit: Oh, and textEdit->setHtml() should be textEdit->setText() since it's Qt 3
    Last edited by jpn; 15th September 2007 at 14:32. Reason: updated contents
    J-P Nurmi

Similar Threads

  1. Explanation to Image Formats
    By sincnarf in forum Qt Programming
    Replies: 13
    Last Post: 6th July 2007, 17:02
  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
  •  
Qt is a trademark of The Qt Company.