[maptips] fix 0,0 size by resizing widget to content when html loaded

This commit is contained in:
nirvn 2018-07-18 09:49:42 +07:00 committed by Mathieu Pellerin
parent 6ffa39d750
commit 95e62036ae
3 changed files with 17 additions and 9 deletions

View File

@ -9336,7 +9336,6 @@ void QgisApp::saveLastMousePosition( const QgsPointXY &p )
mpMaptip->clear( mMapCanvas );
// don't start the timer if the mouse is not over the map canvas
mpMapTipsTimer->start();
//QgsDebugMsg("Started maptips timer");
}
}
}

View File

@ -67,6 +67,7 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
mWebView->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );//Handle link clicks by yourself
mWebView->setContextMenuPolicy( Qt::NoContextMenu ); //No context menu is allowed if you don't need it
connect( mWebView, &QWebView::linkClicked, this, &QgsMapTip::onLinkClicked );
connect( mWebView, &QWebView::loadFinished, this, [ = ]( bool ) { resizeContent(); } );
#endif
mWebView->page()->settings()->setAttribute(
@ -135,6 +136,17 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
mWidget->show();
#if WITH_QTWEBKIT
resizeContent();
#endif
}
void QgsMapTip::resizeContent()
{
// Get the content size
QWebElement container = mWebView->page()->mainFrame()->findFirstElement(
QStringLiteral( "#QgsWebViewContainer" ) );
int width = container.geometry().width();
int height = container.geometry().height();
int scrollbarWidth = mWebView->page()->mainFrame()->scrollBarGeometry(
Qt::Vertical ).width();
int scrollbarHeight = mWebView->page()->mainFrame()->scrollBarGeometry(
@ -142,15 +154,11 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
if ( scrollbarWidth > 0 || scrollbarHeight > 0 )
{
// Get the content size
QWebElement container = mWebView->page()->mainFrame()->findFirstElement(
QStringLiteral( "#QgsWebViewContainer" ) );
int width = container.geometry().width() + 5 + scrollbarWidth;
int height = container.geometry().height() + 5 + scrollbarHeight;
mWidget->resize( width, height );
width += 5 + scrollbarWidth;
height += 5 + scrollbarHeight;
}
#endif
mWidget->resize( width, height );
}
void QgsMapTip::clear( QgsMapCanvas * )

View File

@ -96,5 +96,6 @@ class GUI_EXPORT QgsMapTip : public QWidget
private slots:
void onLinkClicked( const QUrl &url );
void resizeContent();
};
#endif // QGSMAPTIP_H