mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
only show tooltip if required
This commit is contained in:
parent
1f92ad18a8
commit
eefa8d8ae6
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -30,9 +30,8 @@ public:
|
|||
virtual QSize sizeHint() const;
|
||||
virtual QSize minimumSizeHint() const;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
protected:
|
||||
void setElidedText();
|
||||
|
||||
private:
|
||||
QString origText;
|
||||
|
|
Loading…
Reference in New Issue
Block a user