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. Widget does not move when Main Window is resized.
Forum Updated to NodeBB v4.3 + New Features

Widget does not move when Main Window is resized.

Scheduled Pinned Locked Moved Unsolved General and Desktop
widget resize
5 Posts 3 Posters 8.9k 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
    ronyNS
    wrote on 2 Aug 2016, 19:18 last edited by
    #1

    Hi ,
    i am new to Qt and i am struggling with resizing things , i managed to resize my background image according to the Main Window , now i'm trying to properly position my widget when Main Window is resized.

    I want the widget to be positioned in the right place when the Main Window is resized , however , my widget stays in the same place when window is resized .I tried layouts , but layout does not work in my case as it expands the widget according to the Main Window.
    i want the widget to be of the same size but be positioned properly when window is resized or maximized.

    Thanks in advance :)

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 2 Aug 2016, 19:39 last edited by mrjj 8 Feb 2016, 19:39
      #2

      Hi and welcome
      Layouts is normally the way to do such things.
      You can set Maximum/minimum size on your widget to prevent the layout
      from changing the size even when mainwindow get bigger.

      Alternativ you can override (for main win)
      http://doc.qt.io/qt-5/qwidget.html#resizeEvent

      and simply reposition the widget. ( dont use layout in this case)

      R 1 Reply Last reply 3 Aug 2016, 13:38
      0
      • M mrjj
        2 Aug 2016, 19:39

        Hi and welcome
        Layouts is normally the way to do such things.
        You can set Maximum/minimum size on your widget to prevent the layout
        from changing the size even when mainwindow get bigger.

        Alternativ you can override (for main win)
        http://doc.qt.io/qt-5/qwidget.html#resizeEvent

        and simply reposition the widget. ( dont use layout in this case)

        R Offline
        R Offline
        ronyNS
        wrote on 3 Aug 2016, 13:38 last edited by
        #3

        @mrjj

        Hi thanks for the reply.
        Can you tell me how to set the maximum/minimum size on widget. Sorry i'm a beginner.
        And will that solve my problem.?
        My problem is when my window is of normal size, the widget is at the right side , but when i maximize my window my widget stays in the same position on the screen . So when i maximize it , the widget is seen at the center of the window as it stays in the same position.
        I want the widget to be at the right when i maximize the window.
        Hope you understand my problem :)
        thank you:)

        M K 2 Replies Last reply 3 Aug 2016, 20:23
        0
        • R ronyNS
          3 Aug 2016, 13:38

          @mrjj

          Hi thanks for the reply.
          Can you tell me how to set the maximum/minimum size on widget. Sorry i'm a beginner.
          And will that solve my problem.?
          My problem is when my window is of normal size, the widget is at the right side , but when i maximize my window my widget stays in the same position on the screen . So when i maximize it , the widget is seen at the center of the window as it stays in the same position.
          I want the widget to be at the right when i maximize the window.
          Hope you understand my problem :)
          thank you:)

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 3 Aug 2016, 20:23 last edited by mrjj 8 Mar 2016, 20:32
          #4

          @ronyNS
          hi
          you can set in as a property in the right side of designer.
          (select widget first)

          you can also do it from code with

          ui->widgetname->setMinimumHeight/Width
          like in mainwindow constructor after setupUI()

          something like this ?
          https://www.dropbox.com/s/4ud8nnzh3mvclvm/totheright.zip?dl=0

          1 Reply Last reply
          0
          • R ronyNS
            3 Aug 2016, 13:38

            @mrjj

            Hi thanks for the reply.
            Can you tell me how to set the maximum/minimum size on widget. Sorry i'm a beginner.
            And will that solve my problem.?
            My problem is when my window is of normal size, the widget is at the right side , but when i maximize my window my widget stays in the same position on the screen . So when i maximize it , the widget is seen at the center of the window as it stays in the same position.
            I want the widget to be at the right when i maximize the window.
            Hope you understand my problem :)
            thank you:)

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 3 Aug 2016, 22:01 last edited by kshegunov 8 Mar 2016, 22:02
            #5

            Hello @ronyNS,

            My problem is when my window is of normal size, the widget is at the right side , but when i maximize my window my widget stays in the same position on the screen .

            Your main window's central widget has no layout, so your widget is just floating around. Set a layout for the central widget, set the size policy of the widget to Fixed in the designer (the property pane when you select the widget) and set the sizes of the widget in the designer (again the property pane on the right).

            Look up this thread, the docs on the layouts management and if you want the examples.

            Kind regards.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0

            1/5

            2 Aug 2016, 19:18

            • Login

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