How add URL or IMAGE-URL in QTextEdit

242 Views Asked by At

I have a QString, for example "https://google.com", I should convert from QString to QUrl and then add that QUrl in QTextEdit, when i click that URL, it will open https://google.com.

The next question is, is it possible to make an IMAGE-URL? For example: if “https://example.com” opens a clothing site, can I add an IMAGE-URL to QTextEdit so when I click on this image it will open https://example.com, where IMAGE is image of clothes that opens https://example.com

1

There are 1 best solutions below

0
bogdyname On

Use QLabel: https://doc.qt.io/qt-5/qlabel.html

Example:

label->setText("<a href=\"http://example.com/\">Click Here!</a>");
label->setTextFormat(Qt::RichText);
label->setTextInteractionFlags(Qt::TextBrowserInteraction);
label->setOpenExternalLinks(true);