QWidget to display text with small images (icons / emoticons)

Is there such a widget?

I can write my own widget based on QLabeland a layout similar to http://qt-project.org/doc/qt-5/qtwidgets-layouts-flowlayout-example.html , but then I can not select all the text and copy (therefore it's just a bunch of labels).

+3
source share
2 answers

A QLabel property of a text can contain rich text, and an img tag is supported in rich text in Qt.

For instance,

QLabel myLabel("<img src=\":/foo.png\"> Hello, World!");
+3
source

QTextEdit, , . textChanged() QTextCursor, , , HTML-:

QObject::connect(textEdit, SIGNAL(textChanged()), this, SLOT(changePixmap()),Qt::QueuedConnection) ;

void CSmsWidget::changePixmap()
{
     QRegExp reg(":\\)"); // you can improve regular expression
     QTextCursor cursor(textEdit->document()->find(reg));

     if (!cursor.isNull()) 
     {
         cursor.insertHtml("<img src=\":/images/happy_smilie.png\">");
     }
}
0

All Articles