QVBoxLayout - QLabel on top of a Layout
-
Hi,
I have a this widget :
https://www.dropbox.com/s/j9r0bw2zgwqd5wk/layoutNow2.pngI want to fix it so the QLabel (black overlay down) only take a fixed amount of height (20 pixel for example)
Or set the margin of the layout so that it takes everything - 20px...I have tried all kind of layout, spacer item, and i'm failling again at layout management. What would be the easiest way to achieve that? I want it too look like Google chrome loading animation.
Current code :
@Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) {
ui->setupUi(this);widgetLoading = new QWidget(this); QVBoxLayout *vLayout = new QVBoxLayout(widgetLoading); vLayout->setContentsMargins(10, 500, 100, 0); /// Not good, 500px is fixed and result is bad depending on resolution
// QSpacerItem *spacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
// vLayout->addSpacing(400);labelMsg = new QLabel(widgetLoading); labelMsg->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); labelMsg->setAlignment(Qt::AlignBottom | Qt::AlignLeft); labelMsg->hide();
// vLayout->addSpacerItem(spacer);
vLayout->addWidget(labelMsg, Qt::AlignBottom);
ui->gridLayout->addWidget(widgetLoading, 1, 0, 1, 1);
...
}@ -
Fixed using this:
@Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) {
ui->setupUi(this);widgetLoading = new QWidget(this); QVBoxLayout *vLayout = new QVBoxLayout(widgetLoading); QSpacerItem *spacer = new QSpacerItem(200, 200, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); labelMsg = new QLabel(widgetLoading); labelMsg->setMaximumHeight(30); labelMsg->setMaximumWidth(400); labelMsg->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); labelMsg->setAlignment(Qt::AlignBottom | Qt::AlignLeft); labelMsg->hide(); vLayout->addSpacerItem(spacer); vLayout->addWidget(labelMsg, Qt::AlignBottom); ui->gridLayout->addWidget(widgetLoading, 1, 0, 1, 1);@
Probably not the way intented by Qt but if you don't add another dummy widget to take the extra space the widget never go where you want..
-
Great I haven't thought of it, the interface is working, but since my Label is on top of my QWebView, I loose all interaction with the QWebView once the label is shown.. Is there a property for a QWidget to be "transparent" I.E let click pass trough it.
Or i'll just make a small ajax loading icon, that's what you get for being too fancy !
-
Hi,
You can set Qt::WA_TransparentForMouseEvents on your label and you should be good to go
-
You're welcome :)
Happy coding !