import os
import sys
from PyQt5 import QtGui
from PyQt5 import QtWidgets
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
def main():
app = QtWidgets.QApplication(sys.argv)
programWindow = ProgramWindow()
programWindow.show()
sys.exit(app.exec_())
class ProgramWindow(QtWidgets.QMainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
self.setup_main_window()
self.set_window_layout()
def setup_main_window(self):
self.resize( 800, 600 )
self.setWindowTitle( "Test" )
def set_window_layout(self):
self.startSimulationButton = QPushButton( 'Start Simulation' )
horizontalLayout = QHBoxLayout()
horizontalLayout.addWidget( self.startSimulationButton )
horizontalGroupBox = QGroupBox( "My Group" )
horizontalGroupBox.setLayout( horizontalLayout )
main_vertical_layout = QVBoxLayout()
main_vertical_layout.addWidget( horizontalGroupBox )
self.setLayout( main_vertical_layout )
if __name__ == "__main__":
main()
When I run it, it shows a empty window and throws this error on the console:
QWidget::setLayout: Attempting to set QLayout "" on ProgramWindow "", which already has a layout
I already looked on QLayout: Attempting to add QLayout "" to QWidget "", which already has a layout but I do not think I am doing any of that, what wrong with this code?
Commenting out the last line self.setLayout( main_vertical_layout )
fixes it, but of course, does not show anything on the screen.
This code should Create a QGroupBox
with the layout QHBoxLayout
and put the QGroupBox
inside the layout QVBoxLayout
. And the QVBoxLayout
should be attached on my main window:
- QHBoxLayout
- QGroupBox
- QVBoxLayout
- ProgramWindow