reduce max width of a window relative

29 views
Skip to first unread message

c.b...@posteo.jp

unread,
Apr 10, 2015, 8:36:04 PM4/10/15
to wxpytho...@googlegroups.com
This depends especially on SpinCtrl.

The width of the SpinCtrl is much to big. There is enough space for
round about 6 digits or more in the text-field. But I only want to
display 2 digits.

How can I tell SpinCtrl to be smaller?

I don't want to give it fixed values in pixel. This would be quite
dirty because the application can run on a lot of different machines.

So the best would be if the control would calculate its width by its
'max' value. But it doesn't.

So I tried to just half the widht but this code cause in disapearing of
the control. :)

spinctrl.SetMaxSize( (spinctrl.GetMaxSize()[0] / 2,
spinctrl.GetMaxSize()[1]) )

What would you suggest without using fixed pixel values?

Robin Dunn

unread,
Apr 13, 2015, 4:05:51 PM4/13/15
to wxpytho...@googlegroups.com
Have you looked at the value returned from GetMaxSize? (Hint, -1 means
that it is undefined.)

If you're using this in a sizer then you really want to use SetMinSize
instead as that tells the sizer what the smallest best size of the
widget should be, and unless something in the sizer item flags causes it
to be larger then the minsize is the largest the sizer will make it too.
And the minsize overrides the widget's built in best size.

You can get an approximate pixel value for how wide to make the widget
by using sc.GetTextExtent('00').width + N where N is some value you pick
to add extra space for the internal margins, the size of the spin
button, etc.

--
Robin Dunn
Software Craftsman
http://wxPython.org

c.b...@posteo.jp

unread,
Apr 25, 2015, 9:56:14 AM4/25/15
to wxpytho...@googlegroups.com
On 2015-04-13 13:05 Robin Dunn <ro...@alldunn.com> wrote:
> Have you looked at the value returned from GetMaxSize? (Hint, -1
> means that it is undefined.)

SpinCtrl.GetMaxSize() is undocumented
I don't want to check the return value of each function just because it
is undocumented. But we had this topic in the past...

> You can get an approximate pixel value for how wide to make the
> widget by using sc.GetTextExtent('00').width

Ah nice. I remeber this from my C++ times. Very helpfull.

> the size of the spin button, etc.

How can I get the size of the spin buttons? I checked the C++ headers
and find now methode to recieve the "child controls" (text-field and
spin-button).

Werner

unread,
Apr 25, 2015, 11:26:55 AM4/25/15
to wxpytho...@googlegroups.com
On 4/25/2015 15:55, c.b...@posteo.jp wrote:
> On 2015-04-13 13:05 Robin Dunn <ro...@alldunn.com> wrote:
>> Have you looked at the value returned from GetMaxSize? (Hint, -1
>> means that it is undefined.)
> SpinCtrl.GetMaxSize() is undocumented
http://wxpython.org/Phoenix/docs/html/Window.html#Window.GetMaxSize

see the inheritance diagram from class SpinCtrl.

Werner

c.b...@posteo.jp

unread,
Apr 25, 2015, 11:50:54 AM4/25/15
to wxpytho...@googlegroups.com
On 2015-04-25 17:26 Werner <wern...@gmx.ch> wrote:
> On 4/25/2015 15:55, c.b...@posteo.jp wrote:
> > SpinCtrl.GetMaxSize() is undocumented
>
> see the inheritance diagram from class SpinCtrl.

You see the string before the '.'. I mean "SpinCtrl.GetMaxSize" not
"Window.GetMaxSize". And by-the-way: the -1-return-value isn't
documented in "Window.GetMaxSize".

Werner

unread,
Apr 25, 2015, 12:01:17 PM4/25/15
to wxpytho...@googlegroups.com
SpinCtrl inherits from Control and then from Windows, so
SpinCtrl.GetMaxSize is actually implemented in wx.Window.

When you look at the return value of GetMaxSize it has a link to Size
which defines the -1:
http://wxpython.org/Phoenix/docs/html/Size.html#size

Werner

c.b...@posteo.jp

unread,
Apr 26, 2015, 11:55:51 AM4/26/15
to wxpytho...@googlegroups.com
On 2015-04-11 02:35 <c.b...@posteo.jp> wrote:
> This depends especially on SpinCtrl.
>
> The width of the SpinCtrl is much to big. There is enough space for
> round about 6 digits or more in the text-field. But I only want to
> display 2 digits.

This can be done like this:

size = spin.GetSizeFromTextSize(spin.GetTextExtent('00'))
spinCtrl.SetMinSize(size)

This work nearly perfect. The computed width is only 1 pixel to short.
Adding it manually it looks perfect.

Got this hint from here:
<https://forums.wxwidgets.org/viewtopic.php?f=1&t=40925&p=165380#p165380>

I hope someone will test this one-pixel-missing-behaviour with C++. I
will open a bug-report for that.

c.b...@posteo.jp

unread,
Apr 26, 2015, 12:19:22 PM4/26/15
to wxpytho...@googlegroups.com
On 2015-04-26 17:55 <c.b...@posteo.jp> wrote:
> This work nearly perfect. The computed width is only 1 pixel to short.
> Adding it manually it looks perfect.

I did this with wxPhoenix on KDE4 (useing Qt4 I think).

I checked it on LXDE (using Gtk2 I think):
There is no need to add manually a pixel to the width.
Reply all
Reply to author
Forward
0 new messages