diff --git a/widget/croppinglabel.cpp b/widget/croppinglabel.cpp index ef0f54383..656eb2b70 100644 --- a/widget/croppinglabel.cpp +++ b/widget/croppinglabel.cpp @@ -16,24 +16,21 @@ #include "croppinglabel.h" -CroppingLabel::CroppingLabel(QWidget *parent) +CroppingLabel::CroppingLabel(QWidget* parent) : QLabel(parent) { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); } -void CroppingLabel::setText(const QString &text) +void CroppingLabel::setText(const QString& text) { origText = text; - setToolTip(text); - - QLabel::setText(fontMetrics().elidedText(text, Qt::ElideRight, width())); + setElidedText(); } -void CroppingLabel::resizeEvent(QResizeEvent *ev) +void CroppingLabel::resizeEvent(QResizeEvent* ev) { - setText(origText); - + setElidedText(); QLabel::resizeEvent(ev); } @@ -46,3 +43,14 @@ QSize CroppingLabel::minimumSizeHint() const { return QSize(fontMetrics().width("..."), QLabel::minimumSizeHint().height()); } + +void CroppingLabel::setElidedText() +{ + QString elidedText = fontMetrics().elidedText(origText, Qt::ElideRight, width()); + if (elidedText != origText) + setToolTip(origText); + else + setToolTip(QString()); + + QLabel::setText(elidedText); +} diff --git a/widget/croppinglabel.h b/widget/croppinglabel.h index 7ed99704a..decc5ad19 100644 --- a/widget/croppinglabel.h +++ b/widget/croppinglabel.h @@ -30,9 +30,8 @@ public: virtual QSize sizeHint() const; virtual QSize minimumSizeHint() const; -signals: - -public slots: +protected: + void setElidedText(); private: QString origText;