Does such widget exist?
I can write my own widget based on QLabel
s 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).
Does such widget exist?
I can write my own widget based on QLabel
s 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).
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!");
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\">");
}
}