Skip to content

Commit 0fb352b

Browse files
committedJul 19, 2018
[maptips] fix additional wrongly sized widget scenarios
1 parent 1215a58 commit 0fb352b

File tree

3 files changed

+25
-32
lines changed

3 files changed

+25
-32
lines changed
 

‎python/gui/auto_generated/qgsmaptip.sip.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Clear the current maptip if it exists
6262

6363
:param mpMapCanvas: the canvas from which the tip should be cleared.
6464
%End
65+
6566
};
6667
/************************************************************************
6768
* This file has been generated automatically from *

‎src/gui/qgsmaptip.cpp

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@
3737
#include "qgsmaptip.h"
3838

3939
QgsMapTip::QgsMapTip()
40-
4140
{
42-
// init the visible flag
41+
// Init the visible flag
4342
mMapTipVisible = false;
4443
}
4544

@@ -60,6 +59,7 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
6059

6160
delete mWidget;
6261
mWidget = new QWidget( pMapCanvas );
62+
mWidget->setContentsMargins( MARGIN_VALUE, MARGIN_VALUE, MARGIN_VALUE, MARGIN_VALUE );
6363
mWebView = new QgsWebView( mWidget );
6464

6565

@@ -70,24 +70,27 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
7070
connect( mWebView, &QWebView::loadFinished, this, [ = ]( bool ) { resizeContent(); } );
7171
#endif
7272

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 );
7779

7880
QHBoxLayout *layout = new QHBoxLayout;
81+
layout->setContentsMargins( 0, 0, 0, 0 );
7982
layout->addWidget( mWebView );
8083

8184
mWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
8285
mWidget->setLayout( layout );
8386

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
8588
const int MAX_WIDTH = pMapCanvas->geometry().width() / 2;
8689
const int MAX_HEIGHT = pMapCanvas->geometry().height() / 2;
8790
mWidget->setMaximumSize( MAX_WIDTH, MAX_HEIGHT );
8891

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
9194
mWidget->resize( 0, 0 );
9295

9396
backgroundColor = mWidget->palette().base().color().name();
@@ -114,7 +117,8 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
114117

115118
bodyStyle = QString(
116119
"background-color: %1;"
117-
"margin: 0;" ).arg( backgroundColor );
120+
"margin: 0;"
121+
"white-space: nowrap;" ).arg( backgroundColor );
118122

119123
containerStyle = QString(
120124
"display: inline-block;"
@@ -134,30 +138,15 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
134138
lastTipText = tipText;
135139

136140
mWidget->show();
137-
138-
#if WITH_QTWEBKIT
139-
resizeContent();
140-
#endif
141141
}
142142

143143
void QgsMapTip::resizeContent()
144144
{
145145
// Get the content size
146146
QWebElement container = mWebView->page()->mainFrame()->findFirstElement(
147147
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;
161150
mWidget->resize( width, height );
162151
}
163152

@@ -169,7 +158,7 @@ void QgsMapTip::clear( QgsMapCanvas * )
169158
mWebView->setHtml( QString() );
170159
mWidget->hide();
171160

172-
// reset the visible flag
161+
// Reset the visible flag
173162
mMapTipVisible = false;
174163
}
175164

@@ -220,7 +209,7 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPointXY &mapPosition, Qg
220209
return QString();
221210
}
222211

223-
//This slot handles all clicks
212+
// This slot handles all clicks
224213
void QgsMapTip::onLinkClicked( const QUrl &url )
225214
{
226215
QDesktopServices::openUrl( url );

‎src/gui/qgsmaptip.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ class GUI_EXPORT QgsMapTip : public QWidget
7878
* \param mpMapCanvas the canvas from which the tip should be cleared.
7979
*/
8080
void clear( QgsMapCanvas *mpMapCanvas = nullptr );
81+
82+
private slots:
83+
void onLinkClicked( const QUrl &url );
84+
void resizeContent();
85+
8186
private:
8287
// Fetch the feature to use for the maptip text.
8388
// Only the first feature in the search radius is used
@@ -94,8 +99,6 @@ class GUI_EXPORT QgsMapTip : public QWidget
9499
QWidget *mWidget = nullptr;
95100
QgsWebView *mWebView = nullptr;
96101

97-
private slots:
98-
void onLinkClicked( const QUrl &url );
99-
void resizeContent();
102+
const int MARGIN_VALUE = 5;
100103
};
101104
#endif // QGSMAPTIP_H

0 commit comments

Comments
 (0)
Please sign in to comment.