[PyQt] Width() is whack [continued, first message was incomplete]

inhahe inhahe at gmail.com
Mon Jun 1 22:19:49 BST 2015


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.



On Sun, May 31, 2015 at 5:50 PM, inhahe <inhahe at gmail.com> wrote:

> oops, I hit the wrong key and gmail sent the e-mail before I was finished.
> [continued][
> ...the values are 47 and 47, despite the facts that a) they're two
> different sizes as seen visually, and b) the sizes should add up to 200 if
> they were previously 100 and 100, or even better, 640 since that's the
> width of the container widget which they span all the way across.
>
> So width() isn't working very well, and even if the 640 value is
> sufficient, setSizes() still doesn't seem to be working right for some
> reason.
>
> Btw, a number of people have suggested I try Qt Designer, but that's not
> helping because I don't see a QSplitter widget in the menu to add to it,
> and also, I couldn't figure out how to expand a widget to take all
> available room in the designer. I messed with policies making them
> [maximum, maximum] and [expanding, expanding] and the widgets shown weren't
> changed in any way.
>
>
> On Sun, May 31, 2015 at 5:45 PM, inhahe <inhahe at gmail.com> wrote:
>
>> I made a QSplitter, and I want to set the position of the splitter handle
>> such that the right-side widget is a fixed width and the left-side widget
>> takes all the rest of the available space (in the top portion of a
>> QVBoxLayout)
>>
>> One way I tried to do this was to use setSizes and pass [x-y, y]  where x
>> is the width of the entire container widget (using width()) and y is the
>> size i want the right-side widget to be.
>>
>> Apparently x turns out to be 640. Fine, except that it actually puts the
>> splitter handle in the same place (not in the middle, somewhere closer to
>> the right side) whether y is 100, 50, 30, etc.
>>
>> So I tried getting the widths from the individual widgets on the left and
>> right of the splitter, and they're both 100.. even though together on the
>> screen they take up the entire width of the container.  Then, just for fun,
>> I use setSizes (as described above, using the width() of the container
>> widget) and get the widths of the left and right widgets again, and the
>> values are
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150601/4abf2236/attachment.html>


More information about the PyQt mailing list