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. QT6 cannot resize layout
Forum Update on Monday, May 27th 2025

QT6 cannot resize layout

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 1.7k Views
  • 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
    Thijs 0
    wrote on 25 Oct 2022, 20:11 last edited by
    #1

    In QT Designer I have a MainWindow, then I have a centralwidget and in the centralwidget I can put any layout but it will never 'stretch'.
    The layout must be hardcoded heigth and width and thereby my entire application is not able to resize.

    I must say the properties of the layout are all in red and I do not know why, the outline of the layout is also in red and again I do not know why. I have read more than a few tutorials and did not find any resizing application, it seems that fixed height/width is the standard.
    Reading the docs and searching Google and SO, it seems that using a layout in the centralwidget should work and widgets should resize within that, there I can set policies for the priority and direction of resizing etc, all lovely if the layout would work.

    What am I missing here?

    Also asked here on SO: https://stackoverflow.com/questions/74199142/stretching-grid-with-widgets

    # -*- coding: utf-8 -*-
    
    ################################################################################
    ## Form generated from reading UI file 'thijs2.ui'
    ##
    ## Created by: Qt User Interface Compiler version 6.4.0
    ##
    ## WARNING! All changes made in this file will be lost when recompiling UI file!
    ################################################################################
    
    from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
        QMetaObject, QObject, QPoint, QRect,
        QSize, QTime, QUrl, Qt)
    from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
        QFont, QFontDatabase, QGradient, QIcon,
        QImage, QKeySequence, QLinearGradient, QPainter,
        QPalette, QPixmap, QRadialGradient, QTransform)
    from PySide6.QtWidgets import (QApplication, QFrame, QHBoxLayout, QMainWindow,
        QMenuBar, QSizePolicy, QStatusBar, QTextEdit,
        QWidget)
    
    class Ui_MainWindow(object):
        def setupUi(self, MainWindow):
            if not MainWindow.objectName():
                MainWindow.setObjectName(u"MainWindow")
            MainWindow.resize(800, 600)
            self.centralwidget = QWidget(MainWindow)
            self.centralwidget.setObjectName(u"centralwidget")
            sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.centralwidget.sizePolicy().hasHeightForWidth())
            self.centralwidget.setSizePolicy(sizePolicy)
            self.horizontalFrame = QFrame(self.centralwidget)
            self.horizontalFrame.setObjectName(u"horizontalFrame")
            self.horizontalFrame.setGeometry(QRect(259, 228, 231, 241))
            sizePolicy1 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
            sizePolicy1.setHorizontalStretch(0)
            sizePolicy1.setVerticalStretch(0)
            sizePolicy1.setHeightForWidth(self.horizontalFrame.sizePolicy().hasHeightForWidth())
            self.horizontalFrame.setSizePolicy(sizePolicy1)
            self.horizontalLayout = QHBoxLayout(self.horizontalFrame)
            self.horizontalLayout.setObjectName(u"horizontalLayout")
            self.textEdit = QTextEdit(self.horizontalFrame)
            self.textEdit.setObjectName(u"textEdit")
    
            self.horizontalLayout.addWidget(self.textEdit)
    
            MainWindow.setCentralWidget(self.centralwidget)
            self.menubar = QMenuBar(MainWindow)
            self.menubar.setObjectName(u"menubar")
            self.menubar.setGeometry(QRect(0, 0, 800, 30))
            MainWindow.setMenuBar(self.menubar)
            self.statusbar = QStatusBar(MainWindow)
            self.statusbar.setObjectName(u"statusbar")
            MainWindow.setStatusBar(self.statusbar)
    
            self.retranslateUi(MainWindow)
    
            QMetaObject.connectSlotsByName(MainWindow)
        # setupUi
    
        def retranslateUi(self, MainWindow):
            MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
        # retranslateUi
    

    Screenshot_20221025_220223.png
    Screenshot_20221025_220534.png
    Screenshot_20221025_220541.png

    J 1 Reply Last reply 26 Oct 2022, 05:31
    0
    • T Thijs 0
      25 Oct 2022, 20:11

      In QT Designer I have a MainWindow, then I have a centralwidget and in the centralwidget I can put any layout but it will never 'stretch'.
      The layout must be hardcoded heigth and width and thereby my entire application is not able to resize.

      I must say the properties of the layout are all in red and I do not know why, the outline of the layout is also in red and again I do not know why. I have read more than a few tutorials and did not find any resizing application, it seems that fixed height/width is the standard.
      Reading the docs and searching Google and SO, it seems that using a layout in the centralwidget should work and widgets should resize within that, there I can set policies for the priority and direction of resizing etc, all lovely if the layout would work.

      What am I missing here?

      Also asked here on SO: https://stackoverflow.com/questions/74199142/stretching-grid-with-widgets

      # -*- coding: utf-8 -*-
      
      ################################################################################
      ## Form generated from reading UI file 'thijs2.ui'
      ##
      ## Created by: Qt User Interface Compiler version 6.4.0
      ##
      ## WARNING! All changes made in this file will be lost when recompiling UI file!
      ################################################################################
      
      from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
          QMetaObject, QObject, QPoint, QRect,
          QSize, QTime, QUrl, Qt)
      from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
          QFont, QFontDatabase, QGradient, QIcon,
          QImage, QKeySequence, QLinearGradient, QPainter,
          QPalette, QPixmap, QRadialGradient, QTransform)
      from PySide6.QtWidgets import (QApplication, QFrame, QHBoxLayout, QMainWindow,
          QMenuBar, QSizePolicy, QStatusBar, QTextEdit,
          QWidget)
      
      class Ui_MainWindow(object):
          def setupUi(self, MainWindow):
              if not MainWindow.objectName():
                  MainWindow.setObjectName(u"MainWindow")
              MainWindow.resize(800, 600)
              self.centralwidget = QWidget(MainWindow)
              self.centralwidget.setObjectName(u"centralwidget")
              sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
              sizePolicy.setHorizontalStretch(0)
              sizePolicy.setVerticalStretch(0)
              sizePolicy.setHeightForWidth(self.centralwidget.sizePolicy().hasHeightForWidth())
              self.centralwidget.setSizePolicy(sizePolicy)
              self.horizontalFrame = QFrame(self.centralwidget)
              self.horizontalFrame.setObjectName(u"horizontalFrame")
              self.horizontalFrame.setGeometry(QRect(259, 228, 231, 241))
              sizePolicy1 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
              sizePolicy1.setHorizontalStretch(0)
              sizePolicy1.setVerticalStretch(0)
              sizePolicy1.setHeightForWidth(self.horizontalFrame.sizePolicy().hasHeightForWidth())
              self.horizontalFrame.setSizePolicy(sizePolicy1)
              self.horizontalLayout = QHBoxLayout(self.horizontalFrame)
              self.horizontalLayout.setObjectName(u"horizontalLayout")
              self.textEdit = QTextEdit(self.horizontalFrame)
              self.textEdit.setObjectName(u"textEdit")
      
              self.horizontalLayout.addWidget(self.textEdit)
      
              MainWindow.setCentralWidget(self.centralwidget)
              self.menubar = QMenuBar(MainWindow)
              self.menubar.setObjectName(u"menubar")
              self.menubar.setGeometry(QRect(0, 0, 800, 30))
              MainWindow.setMenuBar(self.menubar)
              self.statusbar = QStatusBar(MainWindow)
              self.statusbar.setObjectName(u"statusbar")
              MainWindow.setStatusBar(self.statusbar)
      
              self.retranslateUi(MainWindow)
      
              QMetaObject.connectSlotsByName(MainWindow)
          # setupUi
      
          def retranslateUi(self, MainWindow):
              MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
          # retranslateUi
      

      Screenshot_20221025_220223.png
      Screenshot_20221025_220534.png
      Screenshot_20221025_220541.png

      J Online
      J Online
      jsulm
      Lifetime Qt Champion
      wrote on 26 Oct 2022, 05:31 last edited by
      #2

      @Thijs-0 said in QT6 cannot resize layout:

      in the centralwidget I can put any layout but it will never 'stretch'.

      Because you need to apply a layout to the central widget. You can right click in an empty space in your main window (center widget) and select a layout using "Lay out".

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply 26 Oct 2022, 12:17
      2
      • J jsulm
        26 Oct 2022, 05:31

        @Thijs-0 said in QT6 cannot resize layout:

        in the centralwidget I can put any layout but it will never 'stretch'.

        Because you need to apply a layout to the central widget. You can right click in an empty space in your main window (center widget) and select a layout using "Lay out".

        T Offline
        T Offline
        Thijs 0
        wrote on 26 Oct 2022, 12:17 last edited by
        #3

        @jsulm Yes, thank you, two clicks and now it works great, was looking for such a long time for this..

        1 Reply Last reply
        0

        1/3

        25 Oct 2022, 20:11

        • Login

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