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. Maintain a Square aspect ratio on widget resizing
Forum Updated to NodeBB v4.3 + New Features

Maintain a Square aspect ratio on widget resizing

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 6.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.
  • DannyL408D Offline
    DannyL408D Offline
    DannyL408
    wrote on last edited by DannyL408
    #1

    Hello I have a 1920x1080 window with a frame inside that had 10 qlabels. 50x50 size each

    I want to be able to resize my 1920x1080 window to anything and still be able to maintain the square ratio

    i have tried working with heightforwidth() but i dont think it works on windows+latest versions

    raven-worxR 1 Reply Last reply
    0
    • DannyL408D DannyL408

      Hello I have a 1920x1080 window with a frame inside that had 10 qlabels. 50x50 size each

      I want to be able to resize my 1920x1080 window to anything and still be able to maintain the square ratio

      i have tried working with heightforwidth() but i dont think it works on windows+latest versions

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @DannyL408 said in Maintain a Square aspect ratio on widget resizing:

      i have tried working with heightforwidth() but i dont think it works on windows+latest versions

      did you set a custom size policy with height-for-width enabled?

      QSizePolicy p = this->sizePolicy();
      p.setHeightForWidth( true );
      this->setSizePolicy( p );
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      DannyL408D 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @DannyL408 said in Maintain a Square aspect ratio on widget resizing:

        i have tried working with heightforwidth() but i dont think it works on windows+latest versions

        did you set a custom size policy with height-for-width enabled?

        QSizePolicy p = this->sizePolicy();
        p.setHeightForWidth( true );
        this->setSizePolicy( p );
        
        DannyL408D Offline
        DannyL408D Offline
        DannyL408
        wrote on last edited by DannyL408
        #3

        @raven-worx

        yes i did,
        i did some print statements to see if heightforwidth was being called and it wasnt

        I have an inherited QLabel in the constructor

        QSizePolicy qsp(QSizePolicy::Preferred,QSizePolicy::Preferred);
        qsp.setHeightForWidth(true);
        setSizePolicy(qsp);
        

        QSize custom::sizeHint() const{
        qDebug() << "called";
        return QSize(25,25);
        }
        int custom::heightForWidth ( int w ) const{
        qDebug() << this->size() << w;
        return w;
        }

        problem is they will just take up all the available space and wont be a perfect square on every resolution

        raven-worxR 1 Reply Last reply
        0
        • DannyL408D DannyL408

          @raven-worx

          yes i did,
          i did some print statements to see if heightforwidth was being called and it wasnt

          I have an inherited QLabel in the constructor

          QSizePolicy qsp(QSizePolicy::Preferred,QSizePolicy::Preferred);
          qsp.setHeightForWidth(true);
          setSizePolicy(qsp);
          

          QSize custom::sizeHint() const{
          qDebug() << "called";
          return QSize(25,25);
          }
          int custom::heightForWidth ( int w ) const{
          qDebug() << this->size() << w;
          return w;
          }

          problem is they will just take up all the available space and wont be a perfect square on every resolution

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @DannyL408
          play around with the size policy values. QSizePolicy::Preferred is the most general one and actually lets the layout almost do what it wants.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          DannyL408D 1 Reply Last reply
          0
          • raven-worxR raven-worx

            @DannyL408
            play around with the size policy values. QSizePolicy::Preferred is the most general one and actually lets the layout almost do what it wants.

            DannyL408D Offline
            DannyL408D Offline
            DannyL408
            wrote on last edited by
            #5

            @raven-worx said in Maintain a Square aspect ratio on widget resizing:

            play around with the size policy values. QSizePolicy::Preferred is the most general one and actually lets the layout almost do what it wants.

            none of the sizepolicies seem to work to keep the widget a perfect square on every resolution

            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