简体   繁体   中英

How to remove Qt layout from between two other layouts in Qt Creator's UI designer?

I have the following structure in my Qt form:

UI结构

How can I completely remove the VerticalLayout_1 , so that the gridLayout_8 will became an immediate and only child of page_4 ?

I tried selecting delete from the right click menu, but that deletes the childs of VerticalLayout_1 also. I also tried moving the gridLayout_8 in the drag and drop interface, but since it was the only child of the verticalLayout_1 , I just wasn't able to move it to be in page_4.

One possible way would be to edit the .ui XML file manually to remove the unneeded layout. If you open up your XML file in an editor, you should find something like this:

...
<layout class="QGridLayout" name="page_4">
 <item row="0" column="0">
  <!-- below is the layout you want to remove -->
  <layout class="QVBoxLayout" name="verticalLayout_1">
   <item>
    <layout class="QGridLayout" name="gridLayout_8">
      ...
    </layout>
   </item>
  </layout>
 </item>
</layout>
...

In your case, you just need to remove the <layout> tag and its <item> child, so that the gridLayout_8 becomes a direct child of an <item> of page_4 , ie:

...
<layout class="QGridLayout" name="page_4">
 <item row="0" column="0">
  <layout class="QGridLayout" name="gridLayout_8">
      ...
  </layout>
 </item>
</layout>
...

After that, you can re-open the XML file in QtCreator to make sure everything looks the way it should.

I am not sure if there is a simpler way to achieve the same result from QtCreator. If you know of any, feel free to add an answer.

It can be tricky to select, but in the form, you should've been able to select the gridLayout_8 as a unit and drag it into the page_4 layout. That would leave the verticalLayout_1 still present, but empty, and then you can easily delete it. If the gridLayout_8 layout has zero margins, then it might be impossible to select; you would have to set the margins to something so that the border of gridLayout_8 is separated from the border of verticalLayout_1.

I drag layouts around all the time. The hard part is making the sure the layout is selected rather than something inside it. Just be prepared to undo and try again if you drop in the wrong place or grab the wrong thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM