feat: Add ErrorLabel component.

This commit is contained in:
sunwen
2024-06-20 18:07:34 +08:00
parent fd8632e888
commit 5f1c06314a
10 changed files with 71 additions and 43 deletions

View File

@@ -0,0 +1,17 @@
#include "ErrorLabel.h"
ErrorLabel::ErrorLabel(QWidget* aParent)
: QLabel(aParent)
{
setObjectName("warn");
setWordWrap(true);
}
void ErrorLabel::setErrorText(const QString& aText)
{
QFont font = this->font();
QFontMetrics metrics(font);
int width = metrics.width(aText);
this->setFixedHeight(metrics.lineSpacing() * (width / this->width()) + 30 );
setText(aText);
}

View File

@@ -0,0 +1,14 @@
#ifndef ERRORLABEL_H
#define ERRORLABEL_H
#include <QLabel>
class ErrorLabel : public QLabel
{
public:
ErrorLabel(QWidget* aParent);
void setErrorText(const QString& aText);
};
#endif // ERRORLABEL_H