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. QHBoxLayout does not resize when a child does, also other children keep their positions

QHBoxLayout does not resize when a child does, also other children keep their positions

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 665 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.
  • DorosD Offline
    DorosD Offline
    Doros
    wrote on last edited by Doros
    #1

    Hi,
    I want to put 2 or 3 labels inside a QHBoxLayout, then resize the first label using an animation.
    I succeeded to do that, but sadly not as I expected.
    The problem is that the layout doesn't auto resize to content when I change the first label width. Also, the other labels are not pushed or shifted to right.

    This is the result (Failed result):
    Qt 01.gif
    Qt 02.gif

    I can do that in Java using JavaFX quite easily. So, I get that (Expected result):
    JavaFX 01.gif
    JavaFX 02.gif

    This is my animation code:

    QPropertyAnimation *animation = new QPropertyAnimation(ui->label_1, "size"); 
    animation->setDuration(10000);
    animation->setStartValue(QSize(55, ui->label_1->size().height()));
    animation->setEndValue(QSize(600, ui->label_1->size().height()));
    animation->setEasingCurve(QEasingCurve::InCurve);
    animation->start();
    

    NB: I'm using:

    • Linux Mint
    • Qt 5.15
    • Qt ==> QHBoxLayout, QLabel
    • JavaFX ==> HBox, Label

    Thank you.

    jsulmJ 2 Replies Last reply
    0
    • DorosD Doros

      Hi,
      I want to put 2 or 3 labels inside a QHBoxLayout, then resize the first label using an animation.
      I succeeded to do that, but sadly not as I expected.
      The problem is that the layout doesn't auto resize to content when I change the first label width. Also, the other labels are not pushed or shifted to right.

      This is the result (Failed result):
      Qt 01.gif
      Qt 02.gif

      I can do that in Java using JavaFX quite easily. So, I get that (Expected result):
      JavaFX 01.gif
      JavaFX 02.gif

      This is my animation code:

      QPropertyAnimation *animation = new QPropertyAnimation(ui->label_1, "size"); 
      animation->setDuration(10000);
      animation->setStartValue(QSize(55, ui->label_1->size().height()));
      animation->setEndValue(QSize(600, ui->label_1->size().height()));
      animation->setEasingCurve(QEasingCurve::InCurve);
      animation->start();
      

      NB: I'm using:

      • Linux Mint
      • Qt 5.15
      • Qt ==> QHBoxLayout, QLabel
      • JavaFX ==> HBox, Label

      Thank you.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Doros Please show how you're using layouts.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bonnie
        wrote on last edited by Bonnie
        #3

        Yes, please show more. I guess you are not using layouts in the right way.
        From what you posted, changing the "size" property of widgets in a layout is already wrong, that should be handled by the layout.

        DorosD 1 Reply Last reply
        1
        • DorosD Doros

          Hi,
          I want to put 2 or 3 labels inside a QHBoxLayout, then resize the first label using an animation.
          I succeeded to do that, but sadly not as I expected.
          The problem is that the layout doesn't auto resize to content when I change the first label width. Also, the other labels are not pushed or shifted to right.

          This is the result (Failed result):
          Qt 01.gif
          Qt 02.gif

          I can do that in Java using JavaFX quite easily. So, I get that (Expected result):
          JavaFX 01.gif
          JavaFX 02.gif

          This is my animation code:

          QPropertyAnimation *animation = new QPropertyAnimation(ui->label_1, "size"); 
          animation->setDuration(10000);
          animation->setStartValue(QSize(55, ui->label_1->size().height()));
          animation->setEndValue(QSize(600, ui->label_1->size().height()));
          animation->setEasingCurve(QEasingCurve::InCurve);
          animation->start();
          

          NB: I'm using:

          • Linux Mint
          • Qt 5.15
          • Qt ==> QHBoxLayout, QLabel
          • JavaFX ==> HBox, Label

          Thank you.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Doros As @Bonnie pointed out setting size of a widget which is in a layout is wrong. What you should do is to not to use layouts for this widgets, but size and position them manually.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • B Bonnie

            Yes, please show more. I guess you are not using layouts in the right way.
            From what you posted, changing the "size" property of widgets in a layout is already wrong, that should be handled by the layout.

            DorosD Offline
            DorosD Offline
            Doros
            wrote on last edited by
            #5

            @Bonnie
            @jsulm

            I found a convenient solution, that I'm testing.
            I handled the size of widgets by using strech property to one of them, then I put the layout it self inside an empty widget to let me to set width, because layout doesn't have a resizing property.

            Sans nom 1.jpg

            I'm struggling now to continue my application.

            Thanks both of you.

            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