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)
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/eb58086b-58fc-4bb3-b228-5644826f1026%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I’ve never had to use sizeHint.
What about using a layout?
import sys
from 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 Tue, Mar 28, 2017, 6:51 AM Aren Voorhees <are...@gmail.com> 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 = sizeHintOrself.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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/eb58086b-58fc-4bb3-b228-5644826f1026%40googlegroups.com.
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 python_inside_maya+unsub...@googlegroups.com.
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.
I’ve never had to use sizeHint.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/eb58086b-58fc-4bb3-b228-5644826f1026%40googlegroups.com.
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 python_inside_m...@googlegroups.com.
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.
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBE3gFP%2BcJQ_NzWWrD5e0VH6SRYg83g%3Dbwn9gbrLdVEEg%40mail.gmail.com.