I've tried setting setSizePolicy
to minimum and it didn't work. Here's my main window widget:
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUi()
def initUi(self):
self.resize(const.SCREEN_WIDTH, const.SCREEN_HEIGHT)
self.center()
self.setWindowTitle(const.MAIN_WINDOW_TITLE)
self.centralWidget = QWidget()
self.grid = QGridLayout()
self.centralWidget.setLayout(self.grid)
self.setCentralWidget(self.centralWidget)
self.error_dialog = QErrorMessage()
self.createMenu()
self.addWidgets()
self.show()
def addWidgets(self):
self.wadListLabel = QLabel("Wad List:")
self.wadList = WadList()
self.pathInputLabel = QLabel("GZDoom Path:")
self.pathInput = PathInput()
self.lostSoulLabel = QLabel()
self.lostSoulPixmap = QPixmap("assets/lost_soul_sprite.png")
self.lostSoulLabel.setPixmap(self.lostSoulPixmap)
self.launchButton = QPushButton("Launch")
self.grid.addWidget(self.pathInputLabel, 0, 0)
self.grid.addWidget(self.pathInput, 1, 0)
self.grid.addWidget(self.wadListLabel, 2, 0)
self.grid.addWidget(self.wadList, 3, 0)
self.grid.addWidget(self.lostSoulLabel, 0, 1, Qt.AlignHCenter)
self.grid.addWidget(self.launchButton, 2, 1, Qt.AlignBottom)
self.grid.addWidget(self.launchButton, 3, 1, Qt.AlignBottom)
self.grid.setRowStretch(0, 3)
self.grid.setColumnStretch(0, 3)
self.grid.setColumnStretch(1, 1)
def createMenu(self):
self.openAction = OpenAction(self, self.addWads)
self.exitAction = ExitAction(self)
menuBar = self.menuBar()
fileMenu = menuBar.addMenu('&File')
fileMenu.addAction(self.openAction)
fileMenu.addAction(self.exitAction)
helpMenu = menuBar.addMenu('&Help')
def addWads(self, wads):
existent = False
for wad in wads:
foundItems = self.wadList.findItems(wad, Qt.MatchExactly)
if len(foundItems) > 0:
existent = True
self.error_dialog.showMessage(f"The wad {wad} has already been added to the wad list.")
if not existent:
self.wadList.addItems(wads)
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
How do I avoid this?
Due to the lost soul being in the same column as the path input label, the path input label expands and that's not what I want, I want to block that widget from expanding to the size of the image label. Is there a way to do that using QGridLayout?
EDIT: The height of the self.pathInputLabel
at position 0, 0 expands due to the height of the self.lostSoulLabel
at position 0, 1. How do I keep its height fixed and prevent it to expand?