Allow the user to drag the height of a qtablewidget

129 views
Skip to first unread message

Ben Hearn

unread,
Oct 23, 2015, 10:28:49 AM10/23/15
to Python Programming for Autodesk Maya
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

Marcus Ottosson

unread,
Oct 23, 2015, 11:01:15 AM10/23/15
to python_in...@googlegroups.com
Have a look at QSplitter.

--
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/32be5d8b-e7b3-45d6-b172-df75729b23de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Ben Hearn

unread,
Oct 23, 2015, 11:18:23 AM10/23/15
to Python Programming for Autodesk Maya
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?


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 <ben....@starbreeze.com> 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 python_inside_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

Ben Hearn

unread,
Oct 23, 2015, 11:44:07 AM10/23/15
to Python Programming for Autodesk Maya
Got it. I was creating a new widget and it was casuing issues. I decided to create 3 splitters which solved my issue. Thanks for the tips!

Justin Israel

unread,
Oct 23, 2015, 3:05:39 PM10/23/15
to python_in...@googlegroups.com
On Sat, Oct 24, 2015 at 4:18 AM Ben Hearn <ben....@starbreeze.com> 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 <ben....@starbreeze.com> 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 python_inside_m...@googlegroups.com.



--
Marcus Ottosson
konstr...@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/086e16ab-336d-4205-8469-b50a6cba36b0%40googlegroups.com.

Marcus Ottosson

unread,
Oct 26, 2015, 10:15:46 AM10/26/15
to python_in...@googlegroups.com
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?


For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
Oct 26, 2015, 2:33:27 PM10/26/15
to python_in...@googlegroups.com


On Tue, 27 Oct 2015 3:15 AM Marcus Ottosson <konstr...@gmail.com> 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.



--

Marcus Ottosson
konstr...@gmail.com

To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOACcEFbJMAYjHEf-8S7mLQqDtLHtLBOhHq22r50sftGpg%40mail.gmail.com.

Justin Israel

unread,
Oct 26, 2015, 3:24:55 PM10/26/15
to python_in...@googlegroups.com
On Tue, Oct 27, 2015 at 7:33 AM Justin Israel <justin...@gmail.com> wrote:


On Tue, 27 Oct 2015 3:15 AM Marcus Ottosson <konstr...@gmail.com> 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.

Marcus Ottosson

unread,
Oct 26, 2015, 4:55:10 PM10/26/15
to python_in...@googlegroups.com

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

Here’s what I had in mind.

Inline images 1

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()


For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
Oct 26, 2015, 5:52:29 PM10/26/15
to python_in...@googlegroups.com


On Tue, 27 Oct 2015 9:55 AM Marcus Ottosson <konstr...@gmail.com> 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.



--

Marcus Ottosson
konstr...@gmail.com

To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODPkbs4jEmdtwOvWyV53x%2B-ub5XkapRpYnNXVExOASwow%40mail.gmail.com.

Marcus Ottosson

unread,
Oct 27, 2015, 2:50:25 AM10/27/15
to python_in...@googlegroups.com
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?


For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
Oct 27, 2015, 3:12:50 AM10/27/15
to python_in...@googlegroups.com


On Tue, 27 Oct 2015 7:50 PM Marcus Ottosson <konstr...@gmail.com> 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.



--

Marcus Ottosson
konstr...@gmail.com

To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCyiX53OpfgN0cbnpZfd2vmr2XXn-%3DT7ubnhMEwoe6a6w%40mail.gmail.com.

Marcus Ottosson

unread,
Oct 27, 2015, 3:23:20 AM10/27/15
to python_in...@googlegroups.com

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

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

Which means..

  1. 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.
  2. Extra functionality is included, that is never used.
  3. That is has a layout at all is an implementation detail.


For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
Oct 27, 2015, 5:15:32 AM10/27/15
to python_in...@googlegroups.com


On Tue, 27 Oct 2015 8:23 PM Marcus Ottosson <konstr...@gmail.com> 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


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 <justin...@gmail.com> wrote:


On Tue, 27 Oct 2015 7:50 PM Marcus Ottosson <konstr...@gmail.com> 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 <justin...@gmail.com> wrote:



On Tue, 27 Oct 2015 9:55 AM Marcus Ottosson <konstr...@gmail.com> 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.png



--

Marcus Ottosson
konstr...@gmail.com

Marcus Ottosson

unread,
Oct 27, 2015, 5:26:05 AM10/27/15
to python_in...@googlegroups.com

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?

The whole thing could have been avoided had you admitted that you simply overlooked using the simpler QWidget and layout combination, it happens. :)



For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Marcus Ottosson

unread,
Oct 27, 2015, 6:27:04 AM10/27/15
to python_in...@googlegroups.com
Inline images 1
--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
Oct 27, 2015, 7:53:10 AM10/27/15
to python_in...@googlegroups.com

Lol. I'm not admitting anything!  You can keep your two step item construction. I will continue to use QStackedWidget for this use case!  ::runs away::


Reply all
Reply to author
Forward
0 new messages