[PyQt] Width() is whack - nevermind! solved the problem.

inhahe inhahe at gmail.com
Tue Jun 2 01:36:13 BST 2015


I solved the problem with someone's help.  i ended up calling setSizes
outside the __init__ function and also calling app.processEvents() before
calling QSplitter.sizes()

On Mon, Jun 1, 2015 at 5:19 PM, inhahe <inhahe at gmail.com> wrote:

> i've created a minimal example to show the issues I'm having.
> here's the code: http://pastebin.com/RzEtFKDW
> here's the output I get:
>
> self.width before setsizes: 640
> nicks & text widths before setsizes: 100 100
> splitter width before setsizes: 100
> splitter.geometry.width before setsizes: 100
> self.width after setsizes: 640
> nicks & text widths after setsizes: 47 47
> splitter width after setsizes: 100
> splitter.geometry.width after setsizes: 100
> sizes from channelwindow: [47, 47]
> sizes from main: [47, 47]
> sizes from keypress: [1208, 700]
>
> nothing I get from QWidget.width() and QSplitter.sizes() in various
> conditions is consistent with anything else.
> - the qsplitter's widgets take up all the horizontal space in the window,
> and the window's width() returns 640, yet the sum of the qsplitter's
> widgets' sizes' widths is 200
> - after calling setSizes(), the widgets' width() calls return 47 and 47,
> which is wrong because a) the total doesn't add up to the total width they
> actually take (which is either 640 or 1208+700, depending on what result
> you believe), b) they're both the same (when the splitter handle is NOT in
> the middle of the page), and d) they're even less than the total was before
> calling setSizes() (while the total area taken by the left and right
> widgets doesn't change)
> - when calling QSplitter.sizes() from the keypress event in the bottom
> QTextEdit, a) it returns a different result from when I call it from
> elsewhere, and b) those results are more believable but they don't agree
> with the result from self.width()  (self.width() is the width of the whole
> window)
> it might seem as though this is because app.exec_() isn't running yet in
> the former case, but in my actual application (not this minimal example), i
> do all this while the app is actually running (not via app.exec_() but via
> reactor.run() since I'm using qt4reactor which allows me to use PyQt with
> Twisted), and in my actual application QWidget.sizes() returns [0, 0]!
>
> i'm trying to use sizes information to know what to pass to setSizes(),
> but i can't seem to do what I want.
> the closest I've gotten is to pass the values [self.width()-50, 50], but
> it actually sets the rightmost widget to a width of approximately 80, for
> any number i use that's 80 or below. for larger numbers it actually does
> make the widget larger. but i want it smaller than 80.
>
> i tried calling setFixedWidth() on the right-side widget, and that makes
> it the size I want, but it doesn't actually allow me to move the qsplitter
> handle, which is I want to be able to do
> i tried calling resize() on the right-side widget, and that had no effect.
>
> the only solution I can imagine that might work is to find a place in my
> actual application from which calling QSplitter.sizes() actually returns a
> value like [1208, 700] (like it does in the bottom QEditText's keyPress
> event) and setting it up somehow to call that and setSizes() at that time,
> but that would be a horrible and tenuous hack.
>
>
>
>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150601/7b93b6f7/attachment-0001.html>


More information about the PyQt mailing list