1 Attachment(s)
Adding widget to bottom left corned of existing Widget
Hi,
currently I am trying to achieve something like this:
Attachment 12034
So red widget is centralWidget of my QMainWindow and now I want to add another small widget (yellow one) inside it and put it in bottom left corner.
If I do something like this
Code:
red->setStyleSheet("background:red;");
red->setMaximumSize(400, 400);
layout->addWidget(red);
MyCustomWidget* mainWidget = new MyCustomWidget(this);
mainWidget->setLayout(layout);
setCentralWidget(mainWidget);
I see my widget but it's centered vertically and horizontally inside my MyCustomWidget.
If I try changing "addWidget" line to :
Code:
layout->addWidget(red, 0, Qt::AlignLeft | Qt::AlignBottom);
I don't see my widget anymore.
Could someone tell me why is it happening and how can I fix it?
Is my approach good?
Re: Adding widget to bottom left corned of existing Widget
If your red widget does not have any other children than the yellow widget, then the easiest way is to use a QGridLayout, with two rows and two columns.
The child goes into second row/first colum, a vertical spacer into first row/first column and a horizontal spacer into second row/second column.
Btw, your code snippet is misleading, because you make your "yellow widget" red.
Cheers,
_
Re: Adding widget to bottom left corned of existing Widget
Ups, you are right (red widget is actually yellow :/)
At the end I ended up doing it so.
Thanks!