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. [solved] Issues with resizing widgets inside QHBoxLayout
Forum Update on Monday, May 27th 2025

[solved] Issues with resizing widgets inside QHBoxLayout

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.9k 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.
  • T Offline
    T Offline
    T3STY
    wrote on 27 Jan 2014, 01:24 last edited by
    #1

    I have a QHBoxLayout layout applied to a widget, and then I have many widgets added to it. These widgets have an exapnd button which, when clicked, it either expands the widget size or shrinks it. The purpose is to show more controls when expanded and fewer when shrinked. These widgets only resize horizontally.
    When i try the widgets on their own (not added to the layout) they work perfectly, the widget window is expanded/shrinked as expected. Unfortunately, when I add this widget to the layout expanding the widget is unsuccessful; the layout will keep the initial (shirnked) size of the widget so the widget is actually expanding but visually it will be only partially visible. The problem is the layout is not considering the fact that the widget has changed size.

    -I searched the docs and I found I should set a QSizePolicy to my widget and in this set the horizontal and vertical policies; But in the official documentation QSizePolicy is nowhere to be found. I found "this page":http://qtdocs.narod.ru/4.1.0/doc/html/qsizepolicy.html which seems to be a "copy" of the old documentation from Qt 3, but I haven't been able to use it anyway.- found it right now, still unable to use it...

    Can someone help me setting up the layout so it properly resizes when a widget inside changes size?

    EDIT
    to better understand what I mean please see the image example below:
    !http://img.networkdigitale.com/di/TK4G/lyutrsz.png(image)!
    (the scrollbar on the bottom is still to be implemented using a QScrollArea)

    1 Reply Last reply
    0
    • T Offline
      T Offline
      T3STY
      wrote on 27 Jan 2014, 02:43 last edited by
      #2

      Nevermind, It seems it was fixed with a simple coding trick. I was adding the widgets with
      layout->addWidget(pWidget, 0, Qt::AlignCenter);
      Instead, when I added the widget using the default stretch factor and center values it worked fine:
      layout->addWidget(pWidget);

      1 Reply Last reply
      0

      1/2

      27 Jan 2014, 01:24

      • Login

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