[SOLVED] display an image in textEdit
can i have an example on how to display an image inside of the textEdit widget?
You will have to make an HTML with <img> tag.
can i have an example please because i do not see an image method for textEdit?
It's just ordinary HTML:
There is a an image after this word <img src="/path/to/image" />.
wow that's easy. thank you Volker
how to write the image path so that the image loads on other OS. I need one line of code to be compatible on mac, linux and windows. is this possible?
I guess what i need to know is how to get the absolute path to my program?
You can get the path to your executable with "QApplication::applicationDirPath()":http://developer.qt.nokia.com/doc/qt-4.7/qcoreapplication.html#id-69a34508-b7ba-4b8f-9230-69019ffcb976
path information for the image.
@ui->textEdit->setHtml("<img src="+ QApplication::
applicationDirPath() + "/images.gif>");@
What is that code supposed to do ?
display an image inside of the textEdit and getting the image from the correct file path. the file path will output where your exe is located.
Try something like that:
@QString imagePath = QApplication::applicationDirPath() + "/image.png";
QString html = QString("<img src="%1" />").arg(imagePath);
with the image in the same directory as your executable (don't forget the "/" at the beginning of your relative, since applicationDirPath() doesn't have one at its end).
Edit: you have to use < and > to display < and > in your post :)
thank you alexisdm. I fixed the code in my previous post