In PyQt5, I'm using a QGridLayout to organize some widgets. I want to overlap a QLabel over another, in order to put a PixMap underneath and later drag anotherone an put it on top.
However, I'd like to later access just the label on top in order to clear it or manipulate it in another way, but I don't know how I can call just that one.
I'd like something like the QGridLayout.itemAtPosition(row, column) method, but just to manipulate the last label I added.
Here's what I want in more depth:
from PyQt5.QtWidgets import (QApplication, QWidget, QGridLayout, QLabel)
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
self.init_gui()
def init_gui(self):
self.setGeometry(500, 500, 500, 500)
grid = QGridLayout()
label_1 = QLabel("behind", self)
label_2 = QLabel("TOP", self)
grid.addWidget(label_1, 0, 0)
grid.addWidget(label_2, 0, 0)
# Here, I want to get a reference just to label_2, but this returns a QWidgetItem type.
grid.itemAtPosition(0, 0)
# With this, I would like to then maybe update the label or its content.
if __name__ == "__main__":
app = QApplication([])
form = Window()
form.show()
sys.exit(app.exec())