Skip to content
Permalink
Browse files

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

  • Loading branch information
nirvn committed Jul 18, 2018
1 parent 6ffa39d commit 95e62036ae5d4d0a09e0f16b9ea26da5cc441352
Showing with 17 additions and 9 deletions.
  1. +0 −1 src/app/qgisapp.cpp
  2. +16 −8 src/gui/qgsmaptip.cpp
  3. +1 −0 src/gui/qgsmaptip.h
@@ -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");
}
}
}
@@ -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,22 +136,29 @@ 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(
Qt::Horizontal ).height();

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 * )
@@ -96,5 +96,6 @@ class GUI_EXPORT QgsMapTip : public QWidget

private slots:
void onLinkClicked( const QUrl &url );
void resizeContent();
};
#endif // QGSMAPTIP_H

0 comments on commit 95e6203

Please sign in to comment.
You can’t perform that action at this time.