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. How to vertically align two QLineEdits in independent layouts?
Forum Updated to NodeBB v4.3 + New Features

How to vertically align two QLineEdits in independent layouts?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 394 Views 2 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.
  • R Offline
    R Offline
    rctm
    wrote on last edited by
    #1

    Firstly I'm sorry if this question has been asked before but after extensive research I haven't found a satisfying answer.

    I've got the following widget set up:
    qt layout.png

    All I want to do is to vertically align the two line edits and the following push buttons while keeping the alignment if the widget is resized. It should look something like this:
    qt aligned.png

    For this I've set a minimum size for both line edits and added horizontal spacers to the right of both layouts. This approach only works if the widget isn't resized, because the line edits now stretch at a different rate so the alignment isn't kept.
    When I set the horizontal stretch size policy of both line edits to 1 this is the result:
    qt horizontal stretch .png

    If someone could show me the proper way to do this it would be highly appreciated.

    sierdzioS JonBJ 2 Replies Last reply
    1
    • R rctm

      Firstly I'm sorry if this question has been asked before but after extensive research I haven't found a satisfying answer.

      I've got the following widget set up:
      qt layout.png

      All I want to do is to vertically align the two line edits and the following push buttons while keeping the alignment if the widget is resized. It should look something like this:
      qt aligned.png

      For this I've set a minimum size for both line edits and added horizontal spacers to the right of both layouts. This approach only works if the widget isn't resized, because the line edits now stretch at a different rate so the alignment isn't kept.
      When I set the horizontal stretch size policy of both line edits to 1 this is the result:
      qt horizontal stretch .png

      If someone could show me the proper way to do this it would be highly appreciated.

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @rctm instead of two horizontal layouts, use a single grid layout.

      (Z(:^

      1 Reply Last reply
      2
      • R rctm

        Firstly I'm sorry if this question has been asked before but after extensive research I haven't found a satisfying answer.

        I've got the following widget set up:
        qt layout.png

        All I want to do is to vertically align the two line edits and the following push buttons while keeping the alignment if the widget is resized. It should look something like this:
        qt aligned.png

        For this I've set a minimum size for both line edits and added horizontal spacers to the right of both layouts. This approach only works if the widget isn't resized, because the line edits now stretch at a different rate so the alignment isn't kept.
        When I set the horizontal stretch size policy of both line edits to 1 this is the result:
        qt horizontal stretch .png

        If someone could show me the proper way to do this it would be highly appreciated.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @rctm
        You cannot align the two edits in your picture because they have no relationship to each other, they are in two quite separate layouts.

        As @sierdzio has said you probably have to use a grid layout here, so that their widths can be related.

        If you don't want to do that you could try something like: in each case, put the pushbuttons/radiobuttons to the right into their own horizontal layout (or widget with horizontal layout), and perhaps a layout for the line edit too. Then you would have two widgets/layouts in each case, and you might find that any extra space (from resizing) is distributed evenly between the two areas (line edit on the left, buttons on the right) which results in the line edits lining up. Don't know if that works/is easy, otherwise use grid layout.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rctm
          wrote on last edited by
          #4

          Thanks to both of you for your quick answers. I went with the grid layout. Never considered the grid layout since from my understanding it just consists of horizontal and vertical layouts and I didn't consider the relation.

          1 Reply Last reply
          1
          • R rctm has marked this topic as solved on

          • Login

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