Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QVBoxLayout - QLabel on top of a Layout
Forum Updated to NodeBB v4.3 + New Features

QVBoxLayout - QLabel on top of a Layout

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maximus
    wrote on last edited by
    #1

    Hi,

    I have a this widget :
    https://www.dropbox.com/s/j9r0bw2zgwqd5wk/layoutNow2.png

    I 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);
    ...
    }@


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maximus
      wrote on last edited by
      #2

      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..


      Free Indoor Cycling Software - https://maximumtrainer.com

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maximus
        wrote on last edited by
        #3

        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 !


        Free Indoor Cycling Software - https://maximumtrainer.com

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          You can set Qt::WA_TransparentForMouseEvents on your label and you should be good to go

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maximus
            wrote on last edited by
            #5

            Incredible, Qt has done everything!

            100% working now
            @ widgetLoading->setAttribute(Qt::WA_TransparentForMouseEvents,true);
            loadingMsg->setAttribute(Qt::WA_TransparentForMouseEvents,true);@

            Thank you for the 1000 times :)


            Free Indoor Cycling Software - https://maximumtrainer.com

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You're welcome :)

              Happy coding !

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved