How to make a Qlabel widget in a relative position of its parent widget?

Viewed 59

Problem: I'm going to display a image in a pyqtgraph viewbox, while, i want to add some qlabel at the four corner of the display area, but there is the problem, the upper left corner is OK, but the other three will not change its relative position with the viewbox when the mainwindow change its size, please help.

class AppWindow(QMainWindow, framework.Ui_DD):
    def __init__(self, parent=None):  #
        super(AppWindow, self).__init__(parent)

        self.setupUi(self)
    
        w1 = pg.GraphicsLayoutWidget(parent=self.widget_1, show=True, border=None)
        w2 = pg.GraphicsLayoutWidget(parent=self.widget_2, show=True, border=None)
        w3 = pg.GraphicsLayoutWidget(parent=self.widget_3, show=True, border=None)
        w4 = pg.GraphicsLayoutWidget(parent=self.widget_4, show=True, border=None)
    
        v1a = w1.addViewBox(enableMouse=True, border=None, enableMenu=True, lockAspect=True)
        v1b = w2.addViewBox(enableMouse=True, border=None, enableMenu=True, lockAspect=True)
        v1c = w3.addViewBox(enableMouse=True, border=None, enableMenu=True, lockAspect=True)
        v1d = w4.addViewBox(enableMouse=True, border=None, enableMenu=True, lockAspect=True)
    
        self.GL_1.addWidget(w1)
        self.GL_2.addWidget(w2)
        self.GL_3.addWidget(w3)
        self.GL_4.addWidget(w4)
    
        x = 'demo'
       
        self.label_1 = QtWidgets.QLabel(w1)
      
        self.label_1.setStyleSheet("background-color: rgba(0, 0, 0, 0); color:#FFFF6F")
        self.label_1.setText('UpperLeftText: ' + x + '<br>' +
                             'Demo')
        self.setAutoFillBackground(False)

enter image description here

I'd like to make all four labels always on its relative position to the viewbox when window size chagning.

0 Answers
Related