Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Move widget down after top widget resize

    General and Desktop
    2
    3
    42
    Loading More Posts
    • 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.
    • Jonathan Levanon
      Jonathan Levanon last edited by

      Hi,

      I have a QVBoxLayout that contains a few widgets. When clicking on some button one of the widgets needs to grow downwards, but instead of the widget below it moving, it stays in the same location and they are one on top of the other.
      I've tried changing the parent widget size, but that didn't help.
      To be clear, I change the size of one of the myWidget in the following code -

          QWidget* cWidget = new QWidget();
          QWidget* headers = new QWidget(cWidget);
          initHeaders(headers);
      
          QVBoxLayout clsLay;
          clsLay.addWidget(headers);
          QSqlQuery q = getQuery(type);
          while (q.next()) {
              myWidget* r = new myWidget();
              clsLay.addWidget(r);
          }
          cWidget->setLayout(&clsLay);
          clsLay.setAlignment(Qt::AlignCenter);
          cWidget->setStyleSheet("font-family:Myriad pro; font-size:14px; border:1px solid gray; background-color:rgb(252, 252, 254, 230); margin:0px;");
          cWidget->show();
      
      1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        Your clsLay layout is a local variable. If this code is in some function then that variable goes out of scope and is destroyed so your widget has no layout.

        You should create the layout dynamically with new. The widget takes ownership of the layout so it will clean it up when destroyed.

        1 Reply Last reply Reply Quote 2
        • Jonathan Levanon
          Jonathan Levanon last edited by

          Thanks, didn't think about it :) Solved the problem.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post