fixes html elide issue with InfoFrame
This commit is contained in:
parent
e1dda6c005
commit
c81689d393
@ -37,6 +37,7 @@
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
#include <QToolTip>
|
||||
#include <QTextCursor>
|
||||
|
||||
#include "InfoFrame.h"
|
||||
#include "ui_InfoFrame.h"
|
||||
@ -274,12 +275,31 @@ void InfoFrame::setDescription(QString text)
|
||||
}
|
||||
QString labeltext;
|
||||
labeltext.reserve(300);
|
||||
if (finaltext.length() > 290) {
|
||||
|
||||
|
||||
// elide rich text by getting characters without formatting
|
||||
const int maxCharacterElide = 290;
|
||||
QTextDocument doc;
|
||||
doc.setHtml(text);
|
||||
|
||||
if (doc.characterCount() > maxCharacterElide) {
|
||||
|
||||
ui->descriptionLabel->setOpenExternalLinks(false);
|
||||
ui->descriptionLabel->setTextFormat(Qt::TextFormat::RichText);
|
||||
ui->descriptionLabel->setTextFormat(Qt::TextFormat::RichText); // This allows injecting HTML here.
|
||||
m_description = text;
|
||||
// This allows injecting HTML here.
|
||||
labeltext.append("<html><body>" + finaltext.left(287) + "<a href=\"#mod_desc\">...</a></body></html>");
|
||||
|
||||
const QString elidedPostfix = "<a href=\"#mod_desc\">...</a>";
|
||||
|
||||
// move the cursor to the character elide, doesn't see html
|
||||
QTextCursor cursor(&doc);
|
||||
cursor.movePosition(QTextCursor::End);
|
||||
cursor.setPosition(maxCharacterElide, QTextCursor::KeepAnchor);
|
||||
cursor.removeSelectedText();
|
||||
|
||||
// insert the post fix at the cursor
|
||||
cursor.insertHtml(elidedPostfix);
|
||||
|
||||
labeltext.append(doc.toHtml());
|
||||
QObject::connect(ui->descriptionLabel, &QLabel::linkActivated, this, &InfoFrame::descriptionEllipsisHandler);
|
||||
} else {
|
||||
ui->descriptionLabel->setTextFormat(Qt::TextFormat::AutoText);
|
||||
|
Loading…
x
Reference in New Issue
Block a user