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. Move widget down after top widget resize

Move widget down after top widget resize

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 217 Views
  • 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.
  • J Offline
    J Offline
    Jonathan Levanon
    wrote on 4 Aug 2020, 14:36 last edited by
    #1

    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
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 4 Aug 2020, 14:57 last edited by
      #2

      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
      2
      • J Offline
        J Offline
        Jonathan Levanon
        wrote on 4 Aug 2020, 14:59 last edited by
        #3

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

        1 Reply Last reply
        0

        1/3

        4 Aug 2020, 14:36

        • Login

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