Skip to content

Commit

Permalink
Proper Elide for MultiZim List
Browse files Browse the repository at this point in the history
Add Custom elide marker
  • Loading branch information
ShaopengLin authored and kelson42 committed Oct 30, 2024
1 parent 59940bd commit c26fd20
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/multizimbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,21 @@ ZimItemWidget::ZimItemWidget(QString text, QIcon icon, QWidget *parent) :
const int border = CSS::MultiZimButton::QListWidget::item::border;
const int scrollerWidth = CSS::MultiZimButton::QScrollBar::width;
const int contentWidthExcludeText = iconAndCheckerWidth + totalSpacing + scrollerWidth + border;

textLabel->setFixedWidth(menu->width() - contentWidthExcludeText);
textLabel->setText(text);
const int labelWidth = menu->width() - contentWidthExcludeText;
textLabel->setFixedWidth(labelWidth);

QFontMetrics metrics(textLabel->font());
const int elideMarkerLength = metrics.tightBoundingRect("(...)").width();
const int textLength = labelWidth - elideMarkerLength;
QString elidedText = metrics.elidedText(text, Qt::ElideRight, textLength);
if (elidedText != text)
{
/* Remove built-in elide marker */
elidedText.chop(1);
textLabel->setText(elidedText.trimmed() + "(...)");
}
else
textLabel->setText(text);

layout()->addWidget(iconLabel);
layout()->addWidget(textLabel);
Expand Down

0 comments on commit c26fd20

Please sign in to comment.