1

I have designed a simple GUI in PyQt5 designer. I have used vertical layouts and put all three buttons in it to make it resizable. But when i resize the main window the push buttons do not resize and if i continue resizing they will hide in the min window. Is there any way to make the buttons resizable as the main window resizes? the codes below are for GUI and main files:

GUI (which should be saved as t.py):

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_output(object):
    def setupUi(self, output):
        output.setObjectName("output")
        output.setEnabled(True)
        output.resize(885, 651)
        font = QtGui.QFont()
        font.setPointSize(13)
        output.setFont(font)
        self.verticalLayoutWidget = QtWidgets.QWidget(output)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(270, 80, 321, 341))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.pushButton_2 = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.pushButton_2.setObjectName("pushButton_2")
        self.verticalLayout.addWidget(self.pushButton_2)
        self.pushButton_3 = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.pushButton_3.setObjectName("pushButton_3")
        self.verticalLayout.addWidget(self.pushButton_3)
        self.pushButton = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.pushButton.setObjectName("pushButton")
        self.verticalLayout.addWidget(self.pushButton)

        self.retranslateUi(output)
        QtCore.QMetaObject.connectSlotsByName(output)

    def retranslateUi(self, output):
        _translate = QtCore.QCoreApplication.translate
        output.setWindowTitle(_translate("output", "Dialog"))
        self.pushButton_2.setText(_translate("output", "PushButton"))
        self.pushButton_3.setText(_translate("output", "PushButton"))
        self.pushButton.setText(_translate("output", "PushButton"))

main.py:

import sys
from PyQt5.QtWidgets import QDialog, QApplication
from t import *

class MyAPP(QDialog):
    def __init__(self):
        super().__init__()
        self.ui = Ui_output()
        self.ui.setupUi(self)
        self.show()


if __name__=="__main__":
    app = QApplication(sys.argv)
    w = MyAPP()
    w.show()
    sys.exit(app.exec_())

I really appreciate answers which help me.

Orca
  • 475
  • 1
  • 12
  • 1
    You need to set the main layout, not add a layout from the widget box (those layouts are intended for *nested* layouts). See how to properly [use layout managers in Designer](https://doc.qt.io/qt-5/designer-layouts.html). – musicamante Dec 01 '22 at 19:40
  • @musicamante Yes you are right. I activated the CentralWidget and then put Tab widget in it. it resized well. then i put a group box inside the tabwidget but it does not resize well. What do you prefer to me to do in this situation? – Orca Dec 01 '22 at 20:11
  • 1
    You have to set the layout for the content of each "page", just like you did for the central widget: right click on an empty area of the tab page, and select the proper layout. Note that you'll probably need to do the same for the group box, since you'll certainly want to add other widgets to it. – musicamante Dec 01 '22 at 20:46
  • @musicamante Thank you very much my dear friend. I did as you said an it worked. I really appreciate your help. thank you – Orca Dec 02 '22 at 07:18

0 Answers0