Results 1 to 3 of 3

Thread: Adjusting QWidget space in window once new Label is added to exsisting space.

  1. #1
    Join Date
    Sep 2017
    Posts
    12
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Adjusting QWidget space in window once new Label is added to exsisting space.

    So I currently have a window that has an introduction section on top with a center section that has two labels with plain text editor next to them. Below this I have another section of fixed plain text sections and labels.

    The center section is currently sitting inside of a QWidget, the problem I'm having right now is that i have a pushbutton that when pushed is supposed to set a new label as well as plain text box next to it.

    I can't use any of the layouts as they attempt to expand the plain text bars too far when being adjusted and I don't want users to have to scroll all the way to the right to see all of the text as in a line editor.

    So that I can increase the size of the middle portion of my page without destroying the layout of the bottom section how should I go about this?

    Put the various QObjects inside of a new QWidget? If so how do I tell the QWidget on the bottom to keep it's size while moving down correctly?

    I'm not having any specific coding problems as I'm able to get the plus button to create the objects I need but I just can't get the QWidget to size correctly without everything else disappearing.

    Thank you greatly for any help or examples that you can point me to.

    The center section is currently sitting inside of a QWidget, the problem I'm having right now is that i have a pushbutton that when pushed is supposed to set a new label as well as plain text box next to it.------> (My apologies) inside the middle section

  2. #2
    Join Date
    Sep 2017
    Posts
    12
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Adjusting QWidget space in window once new Label is added to exsisting space.

    I guess a better to rephrase it is this way:
    If I have a QGridLayout that's "on top of" a QWidget I would like to know if there's a way to have these two always have the same lower/upper border with one another so that when I resize the QGridLayout it pushes the QWidget downwards.

    I apologize if the top portion was extremely confusing.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Adjusting QWidget space in window once new Label is added to exsisting space.

    I can't use any of the layouts as they attempt to expand the plain text bars too far when being adjusted and I don't want users to have to scroll all the way to the right to see all of the text as in a line editor.
    You can 1) restrict the maximum size using the properties of the line edit widget in Qt Designer or 2) use a horizontal spacer in the layout to compress the widget to its preferred size.

    You seem to have not realized that you can use layouts within layouts within layouts to get arbitrarily complex relationships between child widgets. Your top-level widget should -always- have a layout that controls the overall size and position of other widgets and layouts within it. If you are manually adding child widget and setting their sizes and positions as your post implies, that's wrong.

    If you want widgets arranged in a vertical stack, use QVBoxLayout. If you want them side-by-side, use QHBoxLayout.

    My strategy for creating a complex nested layout in Qt Designer is this:

    1 - First, start with a very large, empty widget. Set aside the upper left part of this widget as the place that will end up as your final, composed layout. You will use the remaining empty space as a "scratch pad" to create the other layouts that will go in this final layout.

    2 - If you want a group of side-by-side widgets to sit on top of other widgets laid out in a form, first create an empty QVBoxLayout on your widget and drag this to the upper left area.

    3 - In the "scratch pad" area create a QHBoxLayout. Add the side-by-side child widgets to this horizontal layout. Add a horizontal spacer to the right-most end of this layout to push everything to the left.

    4 - In another part of the scratch pad, create a grid layout. Add the other child widgets to the grid, and use spacers if needed to push things into place.

    5 - Drag the hbox layout created in 3) into the vertical layout.

    6 - Drag the grid layout created in 4) into the vertical layout and drop it below the first layout.

    7 - Now you have a vertical layout with two layouts inside it. Continue this procedure until you have the design you want.

    8 - When you are done, resize the main widget until it is about the same size as the outermost layout, then right-click and select "layout vertically" or whatever is appropriate and your outermost layout will be set as the layout for the widget itself. Now when you resize the top-level widget, the layouts within it will also resize in proportion.

    You can also use QSplitter to divide up a widget horizontally or vertically into subwidgets if you can't get what you want using layouts within a single widget.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. The following user says thank you to d_stranz for this useful post:

    seerofsorrow (16th November 2017)

Similar Threads

  1. Reduce space between label and shortcut in menu item
    By franco.amato in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2017, 09:59
  2. Layout automatically adjusting the space dynamically
    By nikhilqt in forum Qt Programming
    Replies: 7
    Last Post: 27th May 2011, 07:49
  3. QTableView empty space or too little space.
    By davemar in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2009, 16:00
  4. Replies: 1
    Last Post: 26th July 2009, 15:08
  5. linking user space and kernel space programs with qmake
    By zielchri in forum Qt Programming
    Replies: 9
    Last Post: 8th March 2006, 23:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.