Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[maptips] fix 0,0 size by resizing widget to content when html loaded
  • Loading branch information
nirvn committed Jul 19, 2018
1 parent 6ffa39d commit 95e6203
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -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");
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions src/gui/qgsmaptip.cpp
Expand Up @@ -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(
Expand Down Expand Up @@ -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 * )
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsmaptip.h
Expand Up @@ -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.