On Tue, Mar 28, 2017, 6:51 AM Aren Voorhees <[email protected]> wrote:
> Hey all, I've been trying to figure this out for a bit without luck - I'm
> trying to find a way to create a recommended or default size for a Pyside
> widget (windows, buttons, etc...). I don't want to use something like
> .setFixedSize() because I still want things to change if the user resizes
> the window. In all my research I always end up being directed toward
> .sizeHint(), but I'm having a hard time figuring out how to use it. In my
> (incorrect) approach, I'd want to be able to do something like:
>
> self.button.sizeHint(75,30)
>
sizeHint() is meant to be a computed value. The method is expected to be
called at any time to ask what the size hint should be, given the current
conditions, such as whether the widget is currently in a layout or has a
parent.
You can also see in the docs that sizeHint() is a virtual method, which
implies that it should be reimplemented in order to specify custom logic.
You can either implement the method yourself in a subclass, or with this
being Python you could dynamically replace the method one-off on any
existing instance:
def sizeHint():
return QSize(75, 30)
self.button.sizeHint = sizeHint
Or
self.button.sizeHint = lambda: QSize(75, 30)
> But clearly it doesn't work like that. The documentation says "This
> property holds the recommended size for the widget.", but I don't get
> where you input the values to recommend the size? Does anyone have an
> example that might help me figure out how to properly set something like
> this up?
>
> Thanks so much!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/eb58086b-58fc-4bb3-b228-5644826f1026%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/eb58086b-58fc-4bb3-b228-5644826f1026%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0uDhWJ1bpFXHq_es6ATJe6WBX_FYQ2u%2BC3_FtZs1zXCQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.