I have a custom control that fills out whatever width a sizer assigns to it, but needs to grow its height dynamically depending on how much data is there. I can’t quite get it to work, as I need to know the width available before I can calculate the height-- and by then the control is already sized by the sizers… and my attempts to get the sizers to re-layout based upon my updated height after calculating it have not gone well (SendSizeEvent, Layout, etc)
Attached is a dummied sample which should show what I’m talking about. The green box fills the width according to the sizer its in as it should, and then calculates how much height it needs to represent all the data in that situation… but remains at the original height.
I have a custom control that fills out whatever width a sizer assigns to it, but needs to grow its height dynamically depending on how much data is there. I can’t quite get it to work, as I need to know the width available before I can calculate the height-- and by then the control is already sized by the sizers… and my attempts to get the sizers to re-layout based upon my updated height after calculating it have not gone well (SendSizeEvent, Layout, etc)
Attached is a dummied sample which should show what I’m talking about. The green box fills the width according to the sizer its in as it should, and then calculates how much height it needs to represent all the data in that situation… but remains at the original height.
Thanks for the advice – For me that didn’t work, as it needed a bit too much knowledge of where the control was to work. I’m using this in several different locations as a generic tagging control.
It did make me think, though, that I just wasn’t calling layout or whatever in the right place – so did a lot more tweaking and for me this works:
mw, mh = self.GetMinSize()
self.SetMinSize((mw, height))
grandparent = self.GetParent().GetParent()
grandparent.Layout()
wx.CallAfter(grandparent.Refresh)
It just feels messy. I was expecting to find a way to propagate a need to resize either from the inside-- a control basically saying, “Hey! I am a different size!” and the sizer its in shifting; and then upwards through the chain… or from the outside, telling te top level window there needs to be shuffling. Not to have to tell the grandparent to get it to work. Eep! Oh well – it works
Thanks for the advice -- For me that didn't work, as it needed a bit too much knowledge of where the control was to work. I'm using this in several different locations as a generic tagging control.
It did make me think, though, that I just wasn't calling layout or whatever in the right place -- so did a lot more tweaking and for me this works:
mw, mh = self.GetMinSize()
self.SetMinSize((mw, height))
grandparent = self.GetParent().GetParent()
grandparent.Layout()
wx.CallAfter(grandparent.Refresh)
It just feels messy. I was expecting to find a way to propagate a need to resize either from the inside-- a control basically saying, "Hey! I am a different size!" and the sizer its in shifting; and then upwards through the chain... or from the outside, telling te top level window there needs to be shuffling. Not to have to tell the grandparent to get it to work. Eep! Oh well -- it works
Nope, sizers don't do anything to bubble up changes like that on their own. Sometimes it seems that it would be nice if they did but I seem to recall a lot of issues with that model of doing things from my Motif days too. So either way there are corner cases that need to be worked around.
···
On Tue, Dec 23, 2008 at 12:08 PM, Steven > Bisseker <steven.bisseker@googlemail.com > <mailto:steven.bisseker@googlemail.com>> wrote:
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!