Play-/Source/ui_qt/ElidedLabel.h

39 lines
1.2 KiB
C
Raw Permalink Normal View History

2017-03-25 21:53:28 +00:00
#pragma once
#include <QLabel>
// MIT - Yash : Speedovation.com [ Picked from internet and modified. if owner needs to add or change license do let me know.]
// as provided by https://wiki.qt.io/Elided_Label
2018-04-30 21:01:23 +01:00
class ElidedLabel : public QLabel
2017-03-25 21:53:28 +00:00
{
2018-04-30 21:01:23 +01:00
Q_OBJECT
2017-03-25 21:53:28 +00:00
public:
2018-04-30 21:01:23 +01:00
ElidedLabel(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
ElidedLabel(const QString& txt, QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
ElidedLabel(const QString& txt, Qt::TextElideMode elideMode = Qt::ElideRight, QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
// Set the elide mode used for displaying text.
void setElideMode(Qt::TextElideMode elideMode)
{
elideMode_ = elideMode;
updateGeometry();
}
// Get the elide mode currently used to display text.
Qt::TextElideMode elideMode() const
{
return elideMode_;
}
// QLabel overrides
void setText(const QString&);
2017-03-25 21:53:28 +00:00
protected: // QLabel overrides
2018-04-30 21:01:23 +01:00
void paintEvent(QPaintEvent*);
void resizeEvent(QResizeEvent*);
// Cache the elided text so as to not recompute it every paint event
void cacheElidedText(int w);
2017-03-25 21:53:28 +00:00
private:
2018-04-30 21:01:23 +01:00
Qt::TextElideMode elideMode_;
QString cachedElidedText;
2017-03-25 21:53:28 +00:00
};