0

I am using Qt Designer to design a simple application. When I created an application without any layout (i.e. vertical, horizontal) the application popped up just fine without warnings.

However, when I switched my application to a vertical layout, my application appears very strangely when called, with the message: "QLayout: Attempting to add QLayout "" to QMainWindow "Dialog", which already has a layout"

I have a strong guess the vertical layout prompted this issue, but I am having a difficult time trying to troubleshoot this.

Any advice would be appreciated!

from PyQt5 import QtCore, QtGui, QtWidgets
import sys

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(624, 409)
        self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
        self.verticalLayout.setObjectName("verticalLayout")
        self.tableWidget = QtWidgets.QTableWidget(Dialog)
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setColumnCount(0)
        self.tableWidget.setRowCount(0)
        self.verticalLayout.addWidget(self.tableWidget)
        self.pushButton = QtWidgets.QPushButton(Dialog)
        self.pushButton.setObjectName("pushButton")
        self.verticalLayout.addWidget(self.pushButton)
        self.pushButton_2 = QtWidgets.QPushButton(Dialog)
        self.pushButton_2.setObjectName("pushButton_2")
        self.verticalLayout.addWidget(self.pushButton_2)

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

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Test GUI"))
        self.pushButton.setText(_translate("Dialog", "Record"))
        self.pushButton_2.setText(_translate("Dialog", "Quit"))

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_Dialog()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
irahorecka
  • 1,447
  • 8
  • 25
  • 1
    change `MainWindow = QtWidgets.QMainWindow()` to `MainWindow = QtWidgets.QDialog()` – eyllanesc Dec 13 '19 at 02:11
  • @eyllanesc perfect! Now the 'record' button is defaulted blue, but the window shows up like a charm. thank you – irahorecka Dec 13 '19 at 02:20
  • 1
    If you want to use QMainWindow then you must use that template in Qt Designer – eyllanesc Dec 13 '19 at 02:27
  • Great - i see what you mean. @eyllanesc, could you help me out and point me to useful articles following this (https://stackoverflow.com/questions/46544780/qtdesigner-changes-will-be-lost-after-redesign-user-interface) where I could implement logic functionalities? It would help out a bunch – irahorecka Dec 13 '19 at 02:32

0 Answers0