GUI issue with QTabBar

57 views
Skip to first unread message

kiteh

unread,
Dec 20, 2018, 8:54:56 PM12/20/18
to Python Programming for Autodesk Maya
Hi all,

Sorry again, that I am asking a GUI question here.

I have created a subclass of QTabBar in which I am trying to populate the tabs via selection from a QMenu (that queries for anything that are of "*_grp")
However I got an issue where the first added item is seemingly behind the button.

I tried adding using a QHBoxLayout but to no avail results. 


Appreciate for any insights.

P.S: Is it possible to do word wrapping on the added tabs?

Marcus Ottosson

unread,
Dec 21, 2018, 1:22:03 AM12/21/18
to python_in...@googlegroups.com

Problem number 1, where does hlay come from? It isn’t defined anywhere in that snippet.

hlay.addWidget(self.add_button)

Problem number 2, adding the widget with the layer to the layout? This line should probably be removed..

hlay.addWidget(self)

And replaced with:

hlay = QtGui.QHBoxLayout(self)

Unless the tab bar already had a layout you could/should use.

hlay = self.layout()

Just double-check it’s the right kind of layout, e.g. a QHBoxLayout.


--
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/f3418d80-dd83-4561-9f90-7975c3aa8a9d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kiteh

unread,
Dec 21, 2018, 7:16:21 PM12/21/18
to Python Programming for Autodesk Maya
Hi Marcus, my bad on this. `hlay` actually refers to the `HBoxLayout()`

I have updated the snippet - https://pastebin.com/raw/EYcMh5hq

When trying out your method where:

class MyTabBar(QtGui.QTabBar):
    def __init__(self, parent=None):
        super(MyTabBar, self).__init__(parent)
        ...
        ...
        hlay = QtGui.QHBoxLayout(self)
        hlay.addWidget(self.add_button)

        ...
        # Or added in the following
        self.setLayout(self)

While it does not seems to error out but the 'add' icon is gone, and I am presented with nothing..

Justin Israel

unread,
Dec 21, 2018, 7:25:11 PM12/21/18
to python_in...@googlegroups.com


On Sat, Dec 22, 2018, 1:16 PM kiteh <kiteh...@gmail.com> wrote:
Hi Marcus, my bad on this. `hlay` actually refers to the `HBoxLayout()`

I have updated the snippet - https://pastebin.com/raw/EYcMh5hq


This part from your snippet isn't correct, for multiple reasons:

self.setTabButton(
    0,
    QtGui.QTabBar.ButtonPosition.RightSide,
    self.add_button
)
hlay = QtGui.QHBoxLayout()
hlay.addWidget(self.add_button)
hlay.addWidget(self)

As documented, setTabButton will take ownership of the button. But then you add it to a layout. Just create it without a parent and pass it to setTabButton. 

Also, the new layout is created but not attached to to manage any widget. You add the button and then self and then the layout does nothing. 

Just get rid of the layout, is my best guess. 


When trying out your method where:

class MyTabBar(QtGui.QTabBar):
    def __init__(self, parent=None):
        super(MyTabBar, self).__init__(parent)
        ...
        ...
        hlay = QtGui.QHBoxLayout(self)
        hlay.addWidget(self.add_button)

        ...
        # Or added in the following
        self.setLayout(self)

While it does not seems to error out but the 'add' icon is gone, and I am presented with nothing..

--
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.

kiteh

unread,
Dec 21, 2018, 7:37:02 PM12/21/18
to Python Programming for Autodesk Maya
Hi Justin,

Just tried it, in which the first item that was populated is behind the 'add' button.
Which is why I am adding in a hboxlayout... in hope that the tabs will appear right by the `add` button

Justin Israel

unread,
Dec 21, 2018, 7:55:12 PM12/21/18
to python_in...@googlegroups.com
You can't really cleanly change the way the QTabBar does its own layout. And adding another layout to it won't fix it. I recommend then creating a subclass of QWidget as your main tab widget, then add an QHBoxLayout and then put a button and a QTabBar into that. Compose your custom widget with child widgets. 

--
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.

kiteh

unread,
Dec 21, 2018, 7:58:28 PM12/21/18
to Python Programming for Autodesk Maya
Instead of `class MyTabBar(QtGui.QTabBar)`, I created it as `class MyTabBar(QtGui.QMainWindow)` and a new variable solely for `QTabBar` and it works...

Even so, (as I am not sure) , generally, to use `QTabBar`, does it always go along with the use of `QTabWidget`?

kiteh

unread,
Dec 21, 2018, 8:03:25 PM12/21/18
to Python Programming for Autodesk Maya
Adding on (hit the "Post" button too fast), I am trying to create a 2 layers of tabs, this is the first level of tabs that I am trying to create, in which based on the creation, it will then populated a second sets of tabs (which will be using QTabWidget) 

Pardon the illustration, but something of the following:
(Say I selected the option - 'food' from the + icon, and within 'food', there are another 3 tabs)

| + |  food | 
| burgers | bread | rice |

Justin Israel

unread,
Dec 21, 2018, 11:15:59 PM12/21/18
to python_in...@googlegroups.com


On Sat, Dec 22, 2018, 1:58 PM kiteh <kiteh...@gmail.com> wrote:
Instead of `class MyTabBar(QtGui.QTabBar)`, I created it as `class MyTabBar(QtGui.QMainWindow)` and a new variable solely for `QTabBar` and it works...

If you want a composable widget for use in other windows and dialogs then you probably want QWidget as your base class. QMainWindow is heavier and meant for top level windows that need menus, toolbars, statusbar, a central widget, and dock window support. 


Even so, (as I am not sure) , generally, to use `QTabBar`, does it always go along with the use of `QTabWidget`?

Read the docs 


'A tab widget provides a tab bar (see QTabBar) and a "page area" that is used to display pages related to each tab.' 

So, one uses the other to compose into a larger widget with more functionality. 


--
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.
Reply all
Reply to author
Forward
0 new messages