From 6f3685eaf0443a973535b725a2a7f2792d98c871 Mon Sep 17 00:00:00 2001 From: fangyefeng <1250890838@qq.com> Date: Wed, 20 Nov 2024 20:01:35 +0800 Subject: [PATCH 1/2] fixed the issue where the original name of a node would be truncated when the name was too long. --- src/elidedlabel.cpp | 16 +++++++--------- src/elidedlabel.h | 1 + src/foldertreedelegateeditor.cpp | 1 - src/labeledittype.cpp | 2 +- src/labeledittype.h | 4 ++-- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/elidedlabel.cpp b/src/elidedlabel.cpp index 4f504a0c..aa034c9c 100644 --- a/src/elidedlabel.cpp +++ b/src/elidedlabel.cpp @@ -3,18 +3,11 @@ #include #include -ElidedLabel::ElidedLabel(QWidget *parent, Qt::WindowFlags f) : QLabel(parent, f) -{ - defaultType = Qt::ElideRight; - eliding = false; - original = ""; -} +ElidedLabel::ElidedLabel(QWidget *parent, Qt::WindowFlags f) : ElidedLabel("", parent, f) { } ElidedLabel::ElidedLabel(const QString &text, QWidget *parent, Qt::WindowFlags f) - : QLabel(text, parent, f) + : QLabel(text, parent, f), defaultType(Qt::ElideRight), eliding(false), original("") { - defaultType = Qt::ElideRight; - eliding = false; setText(text); } @@ -24,6 +17,11 @@ void ElidedLabel::setType(const Qt::TextElideMode type) elide(); } +QString ElidedLabel::text() const +{ + return original; +} + void ElidedLabel::resizeEvent(QResizeEvent *event) { Q_UNUSED(event); diff --git a/src/elidedlabel.h b/src/elidedlabel.h index 8c1bd5fd..d2ed2a16 100644 --- a/src/elidedlabel.h +++ b/src/elidedlabel.h @@ -11,6 +11,7 @@ class ElidedLabel : public QLabel explicit ElidedLabel(const QString &text, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); void setType(const Qt::TextElideMode type); + QString text() const; public slots: void setText(const QString &text); diff --git a/src/foldertreedelegateeditor.cpp b/src/foldertreedelegateeditor.cpp index 5c46b695..a39eb667 100644 --- a/src/foldertreedelegateeditor.cpp +++ b/src/foldertreedelegateeditor.cpp @@ -157,7 +157,6 @@ void FolderTreeDelegateEditor::updateDelegate() { auto displayName = m_index.data(NodeItem::Roles::DisplayText).toString(); QFontMetrics fm(m_titleFont); - displayName = fm.elidedText(displayName, Qt::ElideRight, m_label->contentsRect().width()); QString labelStyle; QString folderIconStyle; diff --git a/src/labeledittype.cpp b/src/labeledittype.cpp index 229f0a98..e5114914 100644 --- a/src/labeledittype.cpp +++ b/src/labeledittype.cpp @@ -3,7 +3,7 @@ #include #include -LabelEditType::LabelEditType(QWidget *parent) : QLabel(parent) +LabelEditType::LabelEditType(QWidget *parent) : ElidedLabel(parent) { setContentsMargins(0, 0, 0, 0); m_editor = new QLineEdit(this); diff --git a/src/labeledittype.h b/src/labeledittype.h index b3816170..485a24a5 100644 --- a/src/labeledittype.h +++ b/src/labeledittype.h @@ -1,10 +1,10 @@ #ifndef LABELEDITTYPE_H #define LABELEDITTYPE_H -#include +#include "elidedlabel.h" class QLineEdit; -class LabelEditType : public QLabel +class LabelEditType : public ElidedLabel { Q_OBJECT public: From 51766ba7c1e088811baeecc2cf5e73ed0e71119c Mon Sep 17 00:00:00 2001 From: fangyefeng <1250890838@qq.com> Date: Fri, 22 Nov 2024 07:19:38 +0800 Subject: [PATCH 2/2] fixed the warning --- src/elidedlabel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elidedlabel.cpp b/src/elidedlabel.cpp index aa034c9c..231a1445 100644 --- a/src/elidedlabel.cpp +++ b/src/elidedlabel.cpp @@ -6,7 +6,7 @@ ElidedLabel::ElidedLabel(QWidget *parent, Qt::WindowFlags f) : ElidedLabel("", parent, f) { } ElidedLabel::ElidedLabel(const QString &text, QWidget *parent, Qt::WindowFlags f) - : QLabel(text, parent, f), defaultType(Qt::ElideRight), eliding(false), original("") + : QLabel(text, parent, f), original(""), defaultType(Qt::ElideRight), eliding(false) { setText(text); }