Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. using the setStretchFactor is changing anything
Forum Updated to NodeBB v4.3 + New Features

using the setStretchFactor is changing anything

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 222 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheShulker
    wrote on last edited by
    #1

    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())
    
    

    error image

    I tried to search it online but it feels like no-one has this problem

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Which version of PyQt6 are you using ?
      On which version of Windows ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved