I've managed to solve that problem:
MainWidget
::MainWidget(QObject* parent
){
mainLayout->addWidget(widget1);
mainLayout->addWidget(widget2);
mainLayout->addWidget(widget3);
setLayout(mainLayout);
}
void MainWidget::addInFront()
{
if (mainLayout)
delete mainLayout;
newWidget = new NewWidget(this);
mainLayout->addWidget(newWidget);
setLayout(mainLayout);
}
MainWidget::MainWidget(QObject* parent)
{
mainLayout = new QVBoxLayout;
mainLayout->addWidget(widget1);
mainLayout->addWidget(widget2);
mainLayout->addWidget(widget3);
setLayout(mainLayout);
}
void MainWidget::addInFront()
{
if (mainLayout)
delete mainLayout;
newWidget = new NewWidget(this);
mainLayout = new QVBoxLayout;
mainLayout->addWidget(newWidget);
setLayout(mainLayout);
}
To copy to clipboard, switch view to plain text mode
NewWidget
::NewWidget(QObject* parent
){
setAutoFillBackground(true);
//setAttribute(Qt::WA_OpaquePaintEvent);
this->setPalette(palette);
newLayout->addWidget(widget0);
setLayout(newLayout);
}
NewWidget::NewWidget(QObject* parent)
{
setAutoFillBackground(true);
//setAttribute(Qt::WA_OpaquePaintEvent);
QPalette palette = this->palette();
palette.setColor(QPalette::Window, QColor(255,255,255,192));
this->setPalette(palette);
newLayout = new QVBoxLayout;
newLayout->addWidget(widget0);
setLayout(newLayout);
}
To copy to clipboard, switch view to plain text mode
That code does everything what I want.
As for placing widgets in front of parent's I've found two useful links:
But now I have to new questions:
- As for Qt::WA_OpaquePaintEvent, am I right that I need that attribute only when re-implement paintEvent and want to draw background by myself?
- And the big one for me. When I follow the described tactic it works only when the margin is -20, otherwise there is some space not covered with the background of NewWidget.

The widget and it's background are pink. How can I resize it to fill the whole window?
Bookmarks