3

Does such widget exist?

I can write my own widget based on QLabels and layout similar to http://qt-project.org/doc/qt-5/qtwidgets-layouts-flowlayout-example.html, but then I can't select all text and copy (because this is just a set of labels).

Martin Delille
  • 11,360
  • 15
  • 65
  • 132
Krzysztof Stanisławek
  • 1,267
  • 4
  • 13
  • 27

2 Answers2

4

A QLabel's text property can have rich text in it, and the img tag is supported in rich text in Qt.

For example,

QLabel myLabel("<img src=\":/foo.png\"> Hello, World!");
sdt
  • 376
  • 2
  • 10
0

You can use a QTextEdit in which when you enter some specific text, it changes to an image like a smiley or emoticon. You should react on textChanged() signal and use QTextCursor to modify the text replacing string with some HTML image tags:

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\">");
     }
}
Nejat
  • 31,784
  • 12
  • 106
  • 138