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. change the size of a widget
Forum Updated to NodeBB v4.3 + New Features

change the size of a widget

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 1.1k 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.
  • E Offline
    E Offline
    EL-jos
    wrote on last edited by
    #1

    greetings to everyone,
    I have a problem that I can't solve, here's the problem: I have a widget(container) that contains a label to display the text but I want to make the size of the widget(container) vary according to the number of characters in the label

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Like this ?
      https://stackoverflow.com/questions/19293507/setting-text-on-a-qlabel-in-a-layout-doesnt-resize

      E 1 Reply Last reply
      0
      • S Offline
        S Offline
        Slawomir_Piernikowski
        wrote on last edited by Slawomir_Piernikowski
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • mrjjM mrjj

          Hi
          Like this ?
          https://stackoverflow.com/questions/19293507/setting-text-on-a-qlabel-in-a-layout-doesnt-resize

          E Offline
          E Offline
          EL-jos
          wrote on last edited by
          #4

          @mrjj Thank you for your answer but except that the code provided in the link you gave me just varies the size of the widget vertically but I want the size of the widget to vary vertically and also horizontally.

          Thank you in advance.

          mrjjM 1 Reply Last reply
          0
          • E EL-jos

            @mrjj Thank you for your answer but except that the code provided in the link you gave me just varies the size of the widget vertically but I want the size of the widget to vary vertically and also horizontally.

            Thank you in advance.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @EL-jos
            ok, did u try with 2x QSizePolicy::MinimumExpanding ?

            E 1 Reply Last reply
            0
            • mrjjM mrjj

              @EL-jos
              ok, did u try with 2x QSizePolicy::MinimumExpanding ?

              E Offline
              E Offline
              EL-jos
              wrote on last edited by
              #6

              @mrjj still nothing the size does not vary horizontally
              Here's my code maybe I misspelled it:

              QVBoxLayout *layout = new QVBoxLayout;
              layout->setSizeConstraint(QLayout::SetMinimumSize);
              this->setLayout(layout);
              for(int i = 0; i < 5; i++)
              {
                  QLabel *label = new QLabel;
                  label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
                  label->setWordWrap(true);
                  label->setText("This is a very long text. ");
                  layout->addWidget(label);
              }
              

              I even reduced the number of characters to see if it works.

              1 Reply Last reply
              0
              • E Offline
                E Offline
                EL-jos
                wrote on last edited by
                #7

                Can someone help me, please?

                mrjjM 1 Reply Last reply
                0
                • E EL-jos

                  Can someone help me, please?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @EL-jos
                  did you try with
                  label->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);

                  1 Reply Last reply
                  1
                  • E Offline
                    E Offline
                    EL-jos
                    wrote on last edited by
                    #9

                    Hello @mrjj
                    Yeah, it's working fine now.
                    Thank you very much for your help.

                    1 Reply Last reply
                    1

                    • Login

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