On Tue, Mar 28, 2017 at 9:17 AM Marcus Ottosson <[email protected]> wrote:
> I’ve never had to use sizeHint. > sizeHint() is related to layouts, when you have more than one widget with "preferred" size and it needs to figure out what that preferred size is: http://doc.qt.io/qt-4.8/qwidget.html#sizePolicy-prop "The default policy is Preferred/Preferred, which means that the widget can be freely resized, but prefers to be the size sizeHint() returns." Implementing the sizeHint() is useful in other situations as well. One is when it is the widget being set into a QDockWidget, where the dock takes the size hint into consideration. http://doc.qt.io/qt-4.8/qdockwidget.html "A QDockWidget acts as a wrapper for its child widget, set with setWidget(). Custom size hints, minimum and maximum sizes and size policies should be implemented in the child widget. QDockWidget will respect them, adjusting its own constraints to include the frame and title." > What about using a layout? > > import sysfrom Qt import QtWidgets > app = QtWidgets.QApplication(sys.argv) > window = QtWidgets.QWidget() > long_button = QtWidgets.QPushButton("Looong") > short_button = QtWidgets.QPushButton("Shrt") > layout = QtWidgets.QHBoxLayout(window) > layout.addWidget(long_button, 4) # Size ratio of 4/1 > layout.addWidget(short_button, 1) # Size ratio of 1/1, long_button takes > majority control > window.resize(400, 50) > window.show() > > > > On 27 March 2017 at 19:31, Justin Israel <[email protected]> wrote: > > > > 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 > <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0uDhWJ1bpFXHq_es6ATJe6WBX_FYQ2u%2BC3_FtZs1zXCQ%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > > For more options, visit https://groups.google.com/d/optout. > > > > > -- > *Marcus Ottosson* > [email protected] > > -- > 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/CAFRtmOBE3gFP%2BcJQ_NzWWrD5e0VH6SRYg83g%3Dbwn9gbrLdVEEg%40mail.gmail.com > <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBE3gFP%2BcJQ_NzWWrD5e0VH6SRYg83g%3Dbwn9gbrLdVEEg%40mail.gmail.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/CAPGFgA0kfaJWKqUXLysmV3%2BJrabpgKVgR_8eYdH4kxB0KN6P9g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
