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. Maintaining fixed aspect ratio for a widget
Forum Updated to NodeBB v4.3 + New Features

Maintaining fixed aspect ratio for a widget

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.3k 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.
  • P Offline
    P Offline
    planarian
    wrote on last edited by
    #1

    There seems to be a fair amount written on this topic, but none of it quite clarifies my problem: I have a widget in a sub-window that I want to keep a fixed aspect ratio. The widget uses a custom layout class that inherits QHBoxLayout and re-implements heightForWidth and hasHeightForWidth. To simplify testing, heightForWidth returns a value equal to its parameter (producing a square). In the widget's size policy, heightForWidth is set to "true." Since I've made these changes, the window continues to resize without restriction, but the internal widget is frozen as a small square, anchored to the middle left-hand side of the window. What am I missing, here?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rcari
      wrote on last edited by
      #2

      When you add the widget to your layout, precise its stretch:
      @hLayout->addWidget( widget, 1 );@

      1 Reply Last reply
      0
      • P Offline
        P Offline
        planarian
        wrote on last edited by
        #3

        No effect, I'm afraid. I wonder, is there anything I need to re-implement for the mouse?

        1 Reply Last reply
        0
        • P Offline
          P Offline
          planarian
          wrote on last edited by
          #4

          I finally gave up on heightForWidth and am now trying to accomplish this with QResizeEvent. If I re-implement it for the widget, it only controls the resizing of the contents of the sub-window, not the sub-window's frame. When I do it for the sub-window (i.e., in a class inheriting QMdiSubWindow), it has no effect! Someone, please throw me a line; I'm running out of ideas....

          [EDIT -- After more testing, I realized that I've got a pointer problem: QMdiArea expects type QMdiSubWindow, so I used an unsafe cast to get it to accept my new class. That means I have a base-class pointer directed at an instance of a derived class, which I think explains why my resize code isn't executing. But I'm not sure how I can get around this. Do I have to re-impement QMdiArea as well?]

          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