0

I have a QTabWidget as my 'central widget' and I would like to use the space that's left over after the tabs have been placed for displaying some text and an image (area in blue below):

Usable area next to tabs

I'm looking for pointers to solutions that will allow me to best make use this space; any ideas?

Saar Drimer
  • 1,171
  • 2
  • 11
  • 24

2 Answers2

1

You can separate the QTabWidget into a QTabBar and a QStackedWidget, and connect them using connect(tab_bar, &QTabBar::currentChanged, stacked_widget, &QStackedWidget::setCurrentIndex);. Then, you can add whatever next to the tab bar like this.

Suggested layout

Minh
  • 1,630
  • 1
  • 8
  • 18
0

A good suggestion from @Minh... that would provide quite a bit of flexibility. However, this answer suggested using the 'corner widget' which sounded better since I won't lose some of the given functionality of QTabWidget.

I gave it a try and it does what I wanted; within my QTabWidget class, I now have:

    # Image and text labels
    qlabel_img = QtWidgets.QLabel()
    pixmap = QtGui.QPixmap('image.png')
    qlabel_img.setPixmap(pixmap)
    qlabel_txt = QtWidgets.QLabel(f"Text under image")

    # Corner widget
    corner_widget = QtWidgets.QWidget()
    corner_layout = QtWidgets.QVBoxLayout()
    corner_layout.addWidget(qlabel_img)
    corner_layout.addWidget(qlabel_txt)
    corner_widget.setLayout(corner_layout)
    self.setCornerWidget(corner_widget)

and so corner_widget is displayed at the top right (right justified) of the tab widget.

Saar Drimer
  • 1,171
  • 2
  • 11
  • 24