On Tue, 27 Oct 2015 8:23 PM Marcus Ottosson <[email protected]> wrote:

Ok, I’d like to provide a counter argument to this convenience, which has
to do with maintenance and perceived performance.

That's fine. I didn't really make a claim that this was the superior way to
go. Just a habit I have for wrapping one widget in another with a layout.
If you feel it warrants a counter argument, it wasn't my intention to try
and defend it.

Here are the contenders.

# Option 1

padder = QStackedWidget() padder.setContentsMargins(6,6,6,6)
padder.addWidget(myWidget)

# Option 2 padder = QWidget() layout = QHBoxLayout(padder)
layout.setContentsMargins(6,6,6,6) layout.addWidget(myWidget)

QStackedWidget is..

a stack of widgets where only one widget is visible at a time - Reference
<http://doc.qt.io/qt-5/qstackedwidget.html>


Which means..

Maintaining this code means either understanding that it is used in place
of a layout because of convenience, or that you need to add a comment
explaining that this is the case, which defeats the purpose of the 1 line
saved.Extra functionality is included, that is never used.That is has a
layout at all is an implementation detail.

I don't feel one needs to have special understanding via comments. Only
knowledge of a QStackedWidget, and what it does.  It's defined clearly in
the docs. There are a ton of methods on QObjects and QWidgets that one may
not end up using, so using a widget for one particular feature does not
feel wrong to me. Also, an implementation detail is something that is
usually not advertised in the public interface, that is relied upon to hold
true, even though it is really subject to change. QStackedWidget fully
documents that it is a convenience widget containing a qstackedlayout. I
don't see it as relying on an implementation details. It's a publicly
documented aspect of the class. It ends up doing the same thing as a
QWidget+QVBoxLayout, since it too wraps a layout.

Don't you think it's a bit of over-thinking to make an analysis out of the
approach, when my reason for using it was kind of a shoulder-shrug that
referred to only needing a single construct to solve the task? I probably
also went that route, thinking that a QStackedLayout only every has to deal
with one visible widget, as opposed to a QVBoxLayout, which is meant to lay
out multiple widgets, vertically. So one could argue that a QStackedLayout
is even a simpler construct :-)

​

On 27 October 2015 at 07:12, Justin Israel <[email protected]> wrote:


On Tue, 27 Oct 2015 7:50 PM Marcus Ottosson <[email protected]> wrote:

I see, and just so we're on the same page, you recommend this over a
QWidget and layout? In any particular circumstance, or just in general?


I guess it's just convenience really. It wraps up about 3 operations in
one.


On 26 October 2015 at 21:52, Justin Israel <[email protected]> wrote:



On Tue, 27 Oct 2015 9:55 AM Marcus Ottosson <[email protected]> wrote:


Too bad you couldn’t post your code, maybe it would have made it easier to
understand your thinking.


No need at this point. Your example is enough to talk about. Basically with
the QStackedWidget, you get rid of the need for creating a QWidget +
QVBoxLayout. It already has the layout and the method to add the content
widget, and responds to content margins

padder = QStackedWidget()
padder.setContentsMargins(6,6,6,6)
padder.addWidget(myWidget)


Here’s what I had in mind.

[image: image.png]




from PySide import QtCore, QtGui class Original(QtGui.QWidget):
"""Arbitrary widget to wrap""" def __init__(self, parent=None):
super(Original, self).__init__(parent)
self.setAttribute(QtCore.Qt.WA_StyledBackground)
self.setStyleSheet("QWidget {background: 'steelblue'}") original =
Original() # Wrapping starts here wrapper = QtGui.QWidget()
wrapper.setStyleSheet("QWidget {background: 'brown'}") layout =
QtGui.QVBoxLayout(wrapper) layout.setContentsMargins(50, 50, 50, 50)
layout.addWidget(original) # Show wrapper, instead of original
wrapper.setMinimumSize(300, 300) wrapper.show()

​

On 26 October 2015 at 19:24, Justin Israel <[email protected]> wrote:

On Tue, Oct 27, 2015 at 7:33 AM Justin Israel <[email protected]>
wrote:


On Tue, 27 Oct 2015 3:15 AM Marcus Ottosson <[email protected]> wrote:

Have been expecting to grasp this with some afterthought, but it hasn't
quite come to me yet.

Why a QStackedWidget, and not just a plain QWidget? Seems a waste, as there
will ever only be a single widget in it?


I expected one would add the widget to a QStackedWidget to keep it centered
at all times, regardless of the size of the stack. But maybe it still works
by only parenting to an outer QWidget? I haven't tested.

Gave it a test with both QWidget and QFrame. Neither of them apply the
contents margins the way the QStackedWidget does, and they don't keep the
widget centered. I used the QStackedWidget as a single visible item layout
that can apply margins around it, without needing to affect the contained
widget properties.




On 23 October 2015 at 20:05, Justin Israel <[email protected]> wrote:


On Sat, Oct 24, 2015 at 4:18 AM Ben Hearn <[email protected]> wrote:


Oh man thanks for the heads up. Got it working as I wanted straight off the
bat. Except the space between the widgets. Any quick solutions?


You can control the spacing independently if you wrap each widget in a
QStackedWidget() and then set then setContentsMagins() on that stack
widget, and add it to the splitter.




On Friday, 23 October 2015 17:01:15 UTC+2, Marcus Ottosson wrote:


Have a look at QSplitter.


On 23 October 2015 at 15:28, Ben Hearn <[email protected]> wrote:


Hello all,

I have a UI that has a few QTableWidgets. The main one is at the top and
the two children are in a horizontal layout below it.

I would like to be able to increase/decrease the height of the main
QTableWidget so the user can change the size as they see fit.

I have the main widgets first column set
to horizontalHeader().setResizeMode(0, QtGui.QHeaderView.Interactive) which
allows the user to change the size of the columns, is there a way to allow
dynamic user based resizing for the entire widget much like the columns?

Cheers,

Ben

-- 
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/32be5d8b-e7b3-45d6-b172-df75729b23de%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/32be5d8b-e7b3-45d6-b172-df75729b23de%40googlegroups.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/086e16ab-336d-4205-8469-b50a6cba36b0%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/086e16ab-336d-4205-8469-b50a6cba36b0%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/CAPGFgA0hCcMSvooLHMmLTKZZdgv%2BCEiomNXPJf4dxdSBimyc5w%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0hCcMSvooLHMmLTKZZdgv%2BCEiomNXPJf4dxdSBimyc5w%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/CAFRtmOACcEFbJMAYjHEf-8S7mLQqDtLHtLBOhHq22r50sftGpg%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOACcEFbJMAYjHEf-8S7mLQqDtLHtLBOhHq22r50sftGpg%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/CAPGFgA30MGSSn9xBPEjRLutPE%3DihOhhWhUdZHfGL2d-c2CGj7Q%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA30MGSSn9xBPEjRLutPE%3DihOhhWhUdZHfGL2d-c2CGj7Q%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/CAFRtmODPkbs4jEmdtwOvWyV53x%2B-ub5XkapRpYnNXVExOASwow%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODPkbs4jEmdtwOvWyV53x%2B-ub5XkapRpYnNXVExOASwow%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/CAPGFgA1YK9zSQOJ%2Bew-1v1Gx7YjZ_BBZToFBg23_HVrUU-DBjw%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1YK9zSQOJ%2Bew-1v1Gx7YjZ_BBZToFBg23_HVrUU-DBjw%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/CAFRtmOCyiX53OpfgN0cbnpZfd2vmr2XXn-%3DT7ubnhMEwoe6a6w%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCyiX53OpfgN0cbnpZfd2vmr2XXn-%3DT7ubnhMEwoe6a6w%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/CAPGFgA1j6_Riu%3D6%2B5mUsErcG9oe2PFXbZoO4x%3DgvdMO6g%3De7EA%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1j6_Riu%3D6%2B5mUsErcG9oe2PFXbZoO4x%3DgvdMO6g%3De7EA%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/CAFRtmOBsBnE%3De0-1rTN3Sc9xaokoKr0pBj4j3r8JAQP6y1Fz0Q%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBsBnE%3De0-1rTN3Sc9xaokoKr0pBj4j3r8JAQP6y1Fz0Q%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/CAPGFgA0PJRkW6DxgR%3DaAYXK1dW7mZGU6A8y%2B5-foRWkLcOKkgQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to