From fab68363d1cf1ea2e8e76eed5c4e3262fd8e48f0 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Thu, 12 Sep 2024 18:22:06 +0500 Subject: [PATCH] UI: TableView::selectedText: Use tool-tip when display text is empty --- src/ui/form/controls/tableview.cpp | 13 +++++++++++-- src/ui/form/controls/tableview.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ui/form/controls/tableview.cpp b/src/ui/form/controls/tableview.cpp index 2c53ba19..40587c7c 100644 --- a/src/ui/form/controls/tableview.cpp +++ b/src/ui/form/controls/tableview.cpp @@ -75,13 +75,22 @@ QString TableView::selectedText() const prevColumn = column; } - const QString s = model()->data(index).toString(); - text.append(s); + text.append(cellText(index)); } return text; } +QString TableView::cellText(const QModelIndex &index) const +{ + const QString displayText = model()->data(index).toString(); + if (!displayText.isEmpty()) + return displayText; + + const QString tooltipText = model()->data(index, Qt::ToolTipRole).toString(); + return tooltipText; +} + void TableView::selectCell(int row, int column) { const auto index = model()->index(row, column); diff --git a/src/ui/form/controls/tableview.h b/src/ui/form/controls/tableview.h index 486ef11b..eaef1eb1 100644 --- a/src/ui/form/controls/tableview.h +++ b/src/ui/form/controls/tableview.h @@ -20,6 +20,7 @@ public: QModelIndexList sortedSelectedIndexes() const; QString selectedText() const; + QString cellText(const QModelIndex &index) const; signals: void currentIndexChanged(const QModelIndex &index);