A widget inside another Qt widget

I am trying to achieve this layout:

enter image description here

where Widget1 is some widget (the central QMainWindow widget), and I want to add a second Widget2 widget on top of it, but it should be in the lower left corner of Widget1.


EDIT: My previous description was not very useful, so I will try to describe it in more detail.

I inherit the QWidget ( class MyClass : public QWidget) class and create my own widget, where I void MyClass ::paintEvent(QPaintEvent *event)draw something on the screen. MyClassthen centralWidgetmine QMainWindow.

Now I want to add a smaller widget (Widget2 in the image) where I would display some video (here I am not asking how to show the video only, how to add this Widget2 to my view). The main thing is that Widget2 is inside (floating in) Widget1.

EDIT2: , , .

+4
1

QGridLayout, :

QGridLayout* layout = new QGridLayout(this);
// 2x2 layout
QWidget* green = new QWidget(this);
green->setStyleSheet("background:green;");
QWidget* yellow = new QWidget(this);
yellow->setStyleSheet("background:yellow;");
QWidget* red = new QWidget(this);
red->setStyleSheet("background:red;");
QWidget* blue = new QWidget(this);
blue->setStyleSheet("background:blue;");
layout->addWidget(green, 0, 0); // Top-Left
layout->addWidget(yellow, 0, 1); // Top-Right
layout->addWidget(red, 1, 0); // Bottom-Left
layout->addWidget(blue, 1, 1); // Bottom-Right
ui->centralWidget->setLayout(layout);

- :

enter image description here

, QGridLayout .

:

QGridLayout* layout = new QGridLayout(this);
// 2x2 layout
QWidget* green = new QWidget(this);
green->setStyleSheet("background:green;");
QWidget* yellow = new QWidget(this);
yellow->setStyleSheet("background:yellow;");
QWidget* red = new QWidget(this);
red->setStyleSheet("background:red;");
QWidget* blue = new QWidget(this);
blue->setStyleSheet("background:blue;");
layout->addWidget(green, 0, 0); // Top-Left
layout->addWidget(yellow, 0, 1); // Top-Right
layout->addWidget(red, 1, 0); // Bottom-Left
layout->addWidget(blue, 1, 1); // Bottom-Right

QWidget* mainWidget = new QWidget(this);
mainWidget->setStyleSheet("background:black;");
mainWidget->setLayout(layout);

QHBoxLayout* centralLayout = new QHBoxLayout(this);
centralLayout->addWidget(mainWidget);
ui->centralWidget->setLayout(centralLayout);

enter image description here

+5

Source: https://habr.com/ru/post/1647993/


All Articles