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. stretching and anchoring of a widget

stretching and anchoring of a widget

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.5k 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.
  • N Offline
    N Offline
    nitzan
    wrote on last edited by
    #1

    In my centralWidget I want to have a widget that is anchored to the top left and is stretching along with the main window (/centralWidget).

    I can't seem to find how to do that inside the QT Creator design view.
    Do I have to do that programmatically?

    (using QT Creator 3.4.3 with QT 5.5.0 under linux)

    Thanks.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      usually you can do this using layouts.
      Can you post a sketch of what you want achieve??

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      N 1 Reply Last reply
      0
      • M mcosta

        Hi,

        usually you can do this using layouts.
        Can you post a sketch of what you want achieve??

        N Offline
        N Offline
        nitzan
        wrote on last edited by
        #3

        The thing is that in the Qt Creator design view there's no way to set anchors or stretching with the layout, as far as I managed to find.

        Here's an image of what I want to have:
        scatch

        The green part is the widget, as you can see even when the window get bigger the widget still fills the width of the parent.

        I hope that makes it clear.
        Thanks.

        1 Reply Last reply
        0
        • David.GD Offline
          David.GD Offline
          David.G
          wrote on last edited by
          #4

          The green widget should be set to preferred (expand width) and fixed (fixed height) with minimum/maximum values.

          Have you tried

          // after ui setup
          ui->centralWidget->layout()->setAlignment(Qt::AlignTop);
          

          on your centralWidget's Layout? More on flags, here.

          I hope that helps

          N 1 Reply Last reply
          0
          • David.GD David.G

            The green widget should be set to preferred (expand width) and fixed (fixed height) with minimum/maximum values.

            Have you tried

            // after ui setup
            ui->centralWidget->layout()->setAlignment(Qt::AlignTop);
            

            on your centralWidget's Layout? More on flags, here.

            I hope that helps

            N Offline
            N Offline
            nitzan
            wrote on last edited by
            #5

            The problem is that the green widget isn't resizing when the window is and so its width stays fixed, even though the sizePolicy for it is:

            • horizontal policy: preferred
            • vertical policy: fixed
            • horizontal stretch: 1
            • vertical stretch: 0

            I haven't used the Qt::AlignTop as the widget stays aligned to top as it is, that's not an issue, only the width is the problem.
            I just want it to fill the parent.

            Thanks.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mcosta
              wrote on last edited by
              #6

              Hi,

              I suggest to use Expanding as Horizontal Policy

              Once your problem is solved don't forget to:

              • Mark the thread as SOLVED using the Topic Tool menu
              • Vote up the answer(s) that helped you to solve the issue

              You can embed images using (http://imgur.com/) or (http://postimage.org/)

              N 1 Reply Last reply
              0
              • M mcosta

                Hi,

                I suggest to use Expanding as Horizontal Policy

                N Offline
                N Offline
                nitzan
                wrote on last edited by
                #7

                @mcosta that seems to have no effect on things.
                the same result as before.

                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