Adjusting size between 2 widgets within a gridlayout (beginner question)



  • I have 2 widgets within a QGridLayout that are touching each other. Each of them take up half of the layout by default, but the user can't adjust the size between them. What I mean is, I'd like the user to be able to drag the separator between the two widgets and adjust the size, so that one size gets bigger and the other gets smaller. I've looked through the docs for a function that allows you to do this with no luck. Any ideas?



  • Try QSplitter instead of QGridLayout.



  • Hi odonnemr,
    When i begin to use Qt, i also have this question before :D
    The answer is:

    1. QGridLayout will handle the position and the size of it's child widget(which in the layout). 2) Basiclly, the position can not be change, but we also have workaround solution. And for size, it can be change, you can have a look at the sizePolicy of the QWidget, but for your requirement, i think we'd better use the workaround.
      a. Use QML to write UI, it's more convenient for UI
      b. Write a container wrapper, which make your widget embeded, and set the container wrapper to the QGridLayout. And do adjust size as usual


  • what kind of container would you recommend chuck?



  • QWidget based is ok. Set the container to the layout, and handle the size change inside the container.



  • Thanks for your help guys, QSplitter did the trick


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.