PDA

View Full Version : Inserting Image into a QTextBox



ashukla
6th September 2007, 13:04
Dear Everyone!
How a way we can insert image into a QTextBox.
regards!

jpn
6th September 2007, 13:19
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.

ashukla
7th September 2007, 05:37
I use Qt3 for this.

jpn
9th September 2007, 09:03
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() (http://doc.trolltech.com/3.3/qtextedit#setMimeSourceFactory).

What did you try so far?

ashukla
15th September 2007, 07:55
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!

jpn
15th September 2007, 09:22
Don't you think it would be appropriate to show some effort on your own?


Animation in QTextEdit (http://wiki.qtcentre.org/index.php?title=Animation_in_QTextEdit) (Qt4)
Drop images on QTextEdit (http://wiki.qtcentre.org/index.php?title=Drop_images_on_QTextEdit) (Qt4)
QTextBrowser with images and CSS (http://wiki.qtcentre.org/index.php?title=QTextBrowser_with_images_and_CSS) (Qt4)

ashukla
15th September 2007, 11:02
Don't you think it would be appropriate to show some effort on your own?


Animation in QTextEdit (http://wiki.qtcentre.org/index.php?title=Animation_in_QTextEdit) (Qt4)
Drop images on QTextEdit (http://wiki.qtcentre.org/index.php?title=Drop_images_on_QTextEdit) (Qt4)
QTextBrowser with images and CSS (http://wiki.qtcentre.org/index.php?title=QTextBrowser_with_images_and_CSS) (Qt4)

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

void dlgImage::pbShowImage_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);

}

jpn
15th September 2007, 11:30
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:


QMimeSourceFactory::defaultFactory()->setPixmap("anything_you_want", pImg);
textEdit->setHtml("<img source=\"anything_you_want\">");


Edit: Oh, and textEdit->setHtml() should be textEdit->setText() since it's Qt 3 :)