Adding one widget on top of another

84 Views Asked by At

I'd like to set a layout where I have a QTableWidget and a semi-transparent QLabel rendered on top of it, that way the table will appear through the semi opaque QLabel image (png).

I've tried using a QBoxLayout:

QWidget* centralWidget = new QWidget;
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, NULL);
QTableWidget* table = new QTableWidget(3, 3);
table->setFixedSize(400, 400);
table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
QLabel* pLabel = new QLabel;
QPixmap pix("./Frame_transp4.png");
pLabel->setPixmap(pix);
layout->addWidget(table);
layout->addWidget(pLabel);
centralWidget->setLayout(layout);
MainWnd.setCentralWidget(centralWidget);

Current result:

label at the bottom of a table widget

Desired result:

Label on top of table widget

I also tried QStackedLayout, but it does not seem to work because it allows to render only one widget at a time.

How can I do that?

0

There are 0 best solutions below