Skip to content

Commit 95e6203

Browse files
committedJul 19, 2018
[maptips] fix 0,0 size by resizing widget to content when html loaded
1 parent 6ffa39d commit 95e6203

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9336,7 +9336,6 @@ void QgisApp::saveLastMousePosition( const QgsPointXY &p )
93369336
mpMaptip->clear( mMapCanvas );
93379337
// don't start the timer if the mouse is not over the map canvas
93389338
mpMapTipsTimer->start();
9339-
//QgsDebugMsg("Started maptips timer");
93409339
}
93419340
}
93429341
}

‎src/gui/qgsmaptip.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
6767
mWebView->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );//Handle link clicks by yourself
6868
mWebView->setContextMenuPolicy( Qt::NoContextMenu ); //No context menu is allowed if you don't need it
6969
connect( mWebView, &QWebView::linkClicked, this, &QgsMapTip::onLinkClicked );
70+
connect( mWebView, &QWebView::loadFinished, this, [ = ]( bool ) { resizeContent(); } );
7071
#endif
7172

7273
mWebView->page()->settings()->setAttribute(
@@ -135,22 +136,29 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
135136
mWidget->show();
136137

137138
#if WITH_QTWEBKIT
139+
resizeContent();
140+
#endif
141+
}
142+
143+
void QgsMapTip::resizeContent()
144+
{
145+
// Get the content size
146+
QWebElement container = mWebView->page()->mainFrame()->findFirstElement(
147+
QStringLiteral( "#QgsWebViewContainer" ) );
148+
int width = container.geometry().width();
149+
int height = container.geometry().height();
138150
int scrollbarWidth = mWebView->page()->mainFrame()->scrollBarGeometry(
139151
Qt::Vertical ).width();
140152
int scrollbarHeight = mWebView->page()->mainFrame()->scrollBarGeometry(
141153
Qt::Horizontal ).height();
142154

143155
if ( scrollbarWidth > 0 || scrollbarHeight > 0 )
144156
{
145-
// Get the content size
146-
QWebElement container = mWebView->page()->mainFrame()->findFirstElement(
147-
QStringLiteral( "#QgsWebViewContainer" ) );
148-
int width = container.geometry().width() + 5 + scrollbarWidth;
149-
int height = container.geometry().height() + 5 + scrollbarHeight;
150-
151-
mWidget->resize( width, height );
157+
width += 5 + scrollbarWidth;
158+
height += 5 + scrollbarHeight;
152159
}
153-
#endif
160+
161+
mWidget->resize( width, height );
154162
}
155163

156164
void QgsMapTip::clear( QgsMapCanvas * )

‎src/gui/qgsmaptip.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,6 @@ class GUI_EXPORT QgsMapTip : public QWidget
9696

9797
private slots:
9898
void onLinkClicked( const QUrl &url );
99+
void resizeContent();
99100
};
100101
#endif // QGSMAPTIP_H

0 commit comments

Comments
 (0)
Please sign in to comment.