From 869fc604b00a9221c48e73c4edfe54113e07fdb0 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Thu, 26 Oct 2017 20:03:16 +0200 Subject: [PATCH] Show comments as tooltips on form Let's face it, where we need the information is not in the layer properties configuration, it's when we enter the data. --- src/gui/qgsattributeform.cpp | 4 ++++ src/gui/qgsattributeform.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/gui/qgsattributeform.cpp b/src/gui/qgsattributeform.cpp index 48866ef0647..527ad31dbbe 100644 --- a/src/gui/qgsattributeform.cpp +++ b/src/gui/qgsattributeform.cpp @@ -1192,6 +1192,7 @@ void QgsAttributeForm::init() tabWidget = nullptr; WidgetInfo widgetInfo = createWidgetFromDef( widgDef, container, mLayer, mContext ); QLabel *label = new QLabel( widgetInfo.labelText ); + label->setToolTip( QStringLiteral( "%1

%2

" ).arg( widgetInfo.labelText, widgetInfo.hint ) ); if ( columnCount > 1 && !widgetInfo.labelOnTop ) { label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); @@ -1277,6 +1278,7 @@ void QgsAttributeForm::init() // This will also create the widget QLabel *l = new QLabel( fieldName ); + l->setToolTip( QStringLiteral( "%1

%2

" ).arg( fieldName, field.comment() ) ); QSvgWidget *i = new QSvgWidget(); i->setFixedSize( 18, 18 ); @@ -1599,6 +1601,7 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt newWidgetInfo.labelOnTop = mLayer->editFormConfig().labelOnTop( fieldDef->idx() ); newWidgetInfo.labelText = mLayer->attributeDisplayName( fieldDef->idx() ); + newWidgetInfo.hint = mLayer->fields().at( fieldDef->idx() ).comment(); newWidgetInfo.showLabel = widgetDef->showLabel(); break; @@ -1687,6 +1690,7 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt else { QLabel *mypLabel = new QLabel( widgetInfo.labelText ); + mypLabel->setToolTip( QStringLiteral( "%1

%2

" ).arg( widgetInfo.labelText, widgetInfo.hint ) ); if ( columnCount > 1 && !widgetInfo.labelOnTop ) { mypLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); diff --git a/src/gui/qgsattributeform.h b/src/gui/qgsattributeform.h index 355cbc28925..fbb16815935 100644 --- a/src/gui/qgsattributeform.h +++ b/src/gui/qgsattributeform.h @@ -304,6 +304,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget QWidget *widget = nullptr; QString labelText; + QString hint; bool labelOnTop = false; bool labelAlignRight = false; bool showLabel = true;