[SOLVED] display an image in textEdit
-
wrote on 8 Aug 2011, 21:41 last edited by
can i have an example on how to display an image inside of the textEdit widget?
-
wrote on 8 Aug 2011, 22:56 last edited by
You will have to make an HTML with <img> tag.
-
wrote on 8 Aug 2011, 23:20 last edited by
can i have an example please because i do not see an image method for textEdit?
-
wrote on 8 Aug 2011, 23:33 last edited by
It's just ordinary HTML:
@
<html>
<body>
There is a an image after this word <img src="/path/to/image" />.
</body>
</html>
@ -
wrote on 8 Aug 2011, 23:42 last edited by
wow that's easy. thank you Volker
-
wrote on 8 Aug 2011, 23:46 last edited by
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?
-
wrote on 9 Aug 2011, 00:52 last edited by
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
-
wrote on 9 Aug 2011, 00:58 last edited by
path information for the image.
@ui->textEdit->setHtml("<img src="+ QApplication::
applicationDirPath() + "/images.gif>");@ -
wrote on 9 Aug 2011, 01:23 last edited by
What is that code supposed to do ?
-
wrote on 9 Aug 2011, 01:29 last edited by
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.
-
wrote on 9 Aug 2011, 01:38 last edited by
Try something like that:
@QString imagePath = QApplication::applicationDirPath() + "/image.png";
QString html = QString("<img src="%1" />").arg(imagePath);
ui->textEdit->setHtml(html);@
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 :)
-
wrote on 9 Aug 2011, 02:30 last edited by
thank you alexisdm. I fixed the code in my previous post
2/12