using the setStretchFactor is changing anything
-
I tried to follow a tutorial about Qt Layouts and they talk about making widgets(buttons) bigger using the setStretchFactor() but when i tried to do the same thing i got an error, all buttons are the same code:
import sys from PyQt6.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout class MainWindow(QWidget): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setWindowTitle('PyQt QVBoxLayout') # create a layout layout = QHBoxLayout() self.setLayout(layout) # create buttons and add them to the layout titles = ['Yes', 'No', 'Cancel'] buttons = [QPushButton(title) for title in titles] for button in buttons: layout.addWidget(button) # set the stretch factors layout.setStretchFactor(buttons[0], 2) layout.setStretchFactor(buttons[1], 2) layout.setStretchFactor(buttons[2], 1) # show the window self.show() if __name__ == '__main__': app = QApplication(sys.argv) window = MainWindow() sys.exit(app.exec())
I tried to search it online but it feels like no-one has this problem
-
Hi,
Which version of PyQt6 are you using ?
On which version of Windows ?