37
37
#include " qgsmaptip.h"
38
38
39
39
QgsMapTip::QgsMapTip ()
40
-
41
40
{
42
- // init the visible flag
41
+ // Init the visible flag
43
42
mMapTipVisible = false ;
44
43
}
45
44
@@ -60,6 +59,7 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
60
59
61
60
delete mWidget ;
62
61
mWidget = new QWidget ( pMapCanvas );
62
+ mWidget ->setContentsMargins ( MARGIN_VALUE, MARGIN_VALUE, MARGIN_VALUE, MARGIN_VALUE );
63
63
mWebView = new QgsWebView ( mWidget );
64
64
65
65
@@ -70,24 +70,27 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
70
70
connect ( mWebView , &QWebView::loadFinished, this , [ = ]( bool ) { resizeContent (); } );
71
71
#endif
72
72
73
- mWebView ->page ()->settings ()->setAttribute (
74
- QWebSettings::DeveloperExtrasEnabled, true );
75
- mWebView ->page ()->settings ()->setAttribute (
76
- QWebSettings::JavascriptEnabled, true );
73
+ mWebView ->page ()->settings ()->setAttribute ( QWebSettings::DeveloperExtrasEnabled, true );
74
+ mWebView ->page ()->settings ()->setAttribute ( QWebSettings::JavascriptEnabled, true );
75
+
76
+ // Disable scrollbars, avoid random resizing issues
77
+ mWebView ->page ()->mainFrame ()->setScrollBarPolicy ( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
78
+ mWebView ->page ()->mainFrame ()->setScrollBarPolicy ( Qt::Vertical, Qt::ScrollBarAlwaysOff );
77
79
78
80
QHBoxLayout *layout = new QHBoxLayout;
81
+ layout->setContentsMargins ( 0 , 0 , 0 , 0 );
79
82
layout->addWidget ( mWebView );
80
83
81
84
mWidget ->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
82
85
mWidget ->setLayout ( layout );
83
86
84
- // assure the map tip is never larger than half the map canvas
87
+ // Assure the map tip is never larger than half the map canvas
85
88
const int MAX_WIDTH = pMapCanvas->geometry ().width () / 2 ;
86
89
const int MAX_HEIGHT = pMapCanvas->geometry ().height () / 2 ;
87
90
mWidget ->setMaximumSize ( MAX_WIDTH, MAX_HEIGHT );
88
91
89
- // start with 0 size,
90
- // the content will automatically make it grow up to MaximumSize
92
+ // Start with 0 size,
93
+ // The content will automatically make it grow up to MaximumSize
91
94
mWidget ->resize ( 0 , 0 );
92
95
93
96
backgroundColor = mWidget ->palette ().base ().color ().name ();
@@ -114,7 +117,8 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
114
117
115
118
bodyStyle = QString (
116
119
" background-color: %1;"
117
- " margin: 0;" ).arg ( backgroundColor );
120
+ " margin: 0;"
121
+ " white-space: nowrap;" ).arg ( backgroundColor );
118
122
119
123
containerStyle = QString (
120
124
" display: inline-block;"
@@ -134,30 +138,15 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
134
138
lastTipText = tipText;
135
139
136
140
mWidget ->show ();
137
-
138
- #if WITH_QTWEBKIT
139
- resizeContent ();
140
- #endif
141
141
}
142
142
143
143
void QgsMapTip::resizeContent ()
144
144
{
145
145
// Get the content size
146
146
QWebElement container = mWebView ->page ()->mainFrame ()->findFirstElement (
147
147
QStringLiteral ( " #QgsWebViewContainer" ) );
148
- int width = container.geometry ().width ();
149
- int height = container.geometry ().height ();
150
- int scrollbarWidth = mWebView ->page ()->mainFrame ()->scrollBarGeometry (
151
- Qt::Vertical ).width ();
152
- int scrollbarHeight = mWebView ->page ()->mainFrame ()->scrollBarGeometry (
153
- Qt::Horizontal ).height ();
154
-
155
- if ( scrollbarWidth > 0 || scrollbarHeight > 0 )
156
- {
157
- width += 5 + scrollbarWidth;
158
- height += 5 + scrollbarHeight;
159
- }
160
-
148
+ int width = container.geometry ().width () + MARGIN_VALUE * 2 ;
149
+ int height = container.geometry ().height () + MARGIN_VALUE * 2 ;
161
150
mWidget ->resize ( width, height );
162
151
}
163
152
@@ -169,7 +158,7 @@ void QgsMapTip::clear( QgsMapCanvas * )
169
158
mWebView ->setHtml ( QString () );
170
159
mWidget ->hide ();
171
160
172
- // reset the visible flag
161
+ // Reset the visible flag
173
162
mMapTipVisible = false ;
174
163
}
175
164
@@ -220,7 +209,7 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPointXY &mapPosition, Qg
220
209
return QString ();
221
210
}
222
211
223
- // This slot handles all clicks
212
+ // This slot handles all clicks
224
213
void QgsMapTip::onLinkClicked ( const QUrl &url )
225
214
{
226
215
QDesktopServices::openUrl ( url );
0 commit comments