'How to set QWidget size to match that of tab parent in PyQt5
I'm trying to make some tabs in my GUI to have a background image cover the whole area. I invoke the general GUI using the following:
self.tabs_widget = LayoutWidgets(self)
self.setCentralWidget(self.tabs_widget)
Afterwards, I use the following code to make some tabs and child widgets.
class LayoutWidgets(QWidget):
def __init__(self, parent):
super(QWidget, self).__init__(parent)
layout = QVBoxLayout(self)
self.tabs = QTabWidget()
self.myUploadProgress = QProgressBar()
layout.addWidget(self.tabs)
layout.addWidget(self.myUploadProgress)
tabNames = ['Tab 1', 'Tab 2', 'Tab 3']
self.tabsIndex = []
for inx, tabName in enumerate(tabNames):
self.tabsIndex.append(QWidget())
self.tabs.addTab(self.tabsIndex[inx], tabName)
self.masterTabLayoutIndex = []
self.masterTitleLabelIndex = []
masterFont = QFont()
masterFont.setPointSize(14)
self.tabsIndex[0].setStyleSheet("background-color: blue")
print(str(self.tabsIndex[0].frameGeometry().width()))
print(str(self.tabsIndex[0].frameGeometry().height()))
I end up getting this as the output. This is fine and all, but the width and height of the tabsIndex[0] widget ends up being 640 and 480 in the print statements.
This doesn't seem to match what I'm seeing.
Also, as I try to add widgets such as labels, I am unable to have them span the whole width and height of this tab section.
How can I add a widget and size it in such a way that it takes up the whole width and height? The ultimate goal is to have a background image fit nicely in the border of the tab, and a few buttons placed on top of the image at certain spots.
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

