Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How to fix the width scale ratio of central widget to mainwindow which contains dockwidgets

    General and Desktop
    mainwindow dockwidget central widget
    2
    3
    1750
    Loading More Posts
    • 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.
    • J
      JohnYork last edited by

      Hello everyone !
      I have a mainwindow with some dockwidgets docked at the right side of it. And I also place a central widget in mainwindow. I want to keep the central widget's width as a fixed scale ratio to mainwindow's width, and the dockwidgets at right side occupy the remained width.

      I found that there is a property in central widget's layout with name of 'layoutStretch', but it seemed that could not make central widget work as I wish.

      Could anyone tell me some instruction ? thanks a lot!

      1 Reply Last reply Reply Quote 1
      • J
        Jakob last edited by

        I don't have a ready-made solution for you, but I can tell you at least that:

        • layoutStretch is the wrong place to look for - this is a technique that allows you to set 'weights' for elements that are handled by the same layout (as far as I understand)
        • I'd start looking for the resizeEvent() member of the QMainWindow class (it is defined in QWidget) - reimplement that function and have it resize the central widget based on your desired scale ratio
        J 1 Reply Last reply Reply Quote 0
        • J
          JohnYork @Jakob last edited by

          @Jakob
          Thanks, Mr. Jakob. I'd tried to resize central widget in resizeEvent(), I found it seemed that setting the geometry of the central widget's layout could work, but not worked good completely. One of the problems is : the docked widgets's width do not change synchronously, this problem cause spacing or overlapping appeares between central widget and docking widgets while resizing mainwindow.

          I thought maybe I should call 'updateGeometry' for every docked widget, but I have not enough time to verify this guess. would you please tell me?

          Well, there is another question about dockwidget and mainwindow:
          I found there was an internal splitter between central widget and docking widgets, and if I pressed mouse left button and pulled it to another position, the docking widgets's width would be fixed and could only be changed by pulling the splitter. This problem makes my purpose to unreached too. How can I work around it?

          1 Reply Last reply Reply Quote 0
          • First post
            Last post