[PyQt] Scrollbars appearing when not needed?

David Boddie david at boddie.org.uk
Sat May 17 15:05:29 BST 2014


On Fri, 16 May 2014 14:26:50 +0100, Chris Wood wrote:
> 
> On 16/05/2014 11:54, David Boddie wrote:
> > On Thu May 15 16:42:06 BST 2014, Chris Wood wrote:

[...]

> >>         frame.setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
> >>         frame.setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
> >>
> > What is frame? Is it the QWebView?
> 
> Yes - it is the QWebView

OK.

> >> confirms that the QWebView is the correct size, and that the border is
> >> visible (i.e. the webpage is not larger than 202x202).
> >> 
> >> Why are the scrollbars appearing? Is this documented / expected
> >> behaviour?
> > 
> > Do they appear when you disable them using the two lines of code above?
> 
> No - they disappear totally and don't appear when the QMainWindow is 
> resized.

Is that the desired behaviour, or would you prefer it if they appeared when
the window is too small?

> > There may be other decoration that reduces the space available to the
> > widget or its contents. Have you verified that the QWebView is actually
> > 202 x 202 pixels when the application runs?
> 
> Unless there's something else I've missed, I'd have thought the fact 
> that the border appears (and that there is no whitespace around it) does 
> confirm thatthe QWebView is 202 x 202 pixels?

It was just something I would check if I was experiencing a similar problem.
There's no guarantee that the view would be exactly that size unless you
explicitly give it a fixed size. At least, I would be concerned about other
widgets that the view is sharing the space with in the same parent widget.

As for the scrollbars appearing by default, even if you have enough space
to show the contents of the view: it may be the normal behaviour but I doubt
it is documented. The workaround you used - disable the scrollbars - may be
good enough to use if you can guarantee that the view won't be smaller than
202 x 202 pixels. You could also set the minimum size to ensure that will be
the case.

David


More information about the PyQt mailing list