From this answer I have code that adds a number of Widgets to a PyQt5 GUI:
I would like to add another widget just in this configuration:
I was trying to play around with QGridLayout()
, for a simplified version of the problem (MWE below).
What I tried (MWE below). I get something like this (plots all squashed on one side):
and varying the grid coordinates has no effect whatsoever.
MWE:
import PyQt5
from PyQt5 import QtGui, QtCore
import pyqtgraph as pg
import sys
import numpy as np
width = 1000
height = 500
class layout():
def setup(self, window):
self.window = window
self.window.resize(width, height)
grid = PyQt5.QtWidgets.QGridLayout()
self.dialogue = QtGui.QTextEdit()
grid.addWidget(self.dialogue , 100, 0)
self.plot = pg.GraphicsLayoutWidget(self.window)
grid.addWidget(self.plot , 200, 200)
class Window(pg.Qt.QtGui.QMainWindow, layout):
def __init__(self, shot = None):
super(Window, self).__init__()
self.setup(self)
self.show()
if __name__ == '__main__':
app = pg.Qt.QtGui.QApplication([])
Window()
sys.exit(app.exec_())
The errors in the code provided by the OP are:
The layout (QGridLayout) was never set in a widget. The Qt layouts are not visual elements but managers of the geometry of the widgets.
A centralWidget must be set if a QMainWindow is used.
Anyway, that problem has nothing to do with the initial problem.
Probably (since the OP does not provide any attempt to the initial goal) the error is that it is thought that adding the same widget 2 times will create 2 copies but it is not, when you add a widget to a layout then it will be removed from its previous position. The solution is to create 2 widgets. For this, it is better to create a class that allows to implement this logic in a simple way.