QT - 在右下角放置按钮 [英] QT - Place Buttons on Bottom Right

查看:79
本文介绍了QT - 在右下角放置按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试放置一组按钮,以便它们固定在屏幕的右下角.我的问题是,每当我调整屏幕大小时,按钮都不会锚定在右下角,而是停留在当前位置.

I am trying to place a set of buttons so that they are anchored to the bottom right of the screen. My problem is that whenever I resize the screen, the buttons are not anchored to the bottom right, but stay in its current position.

我在水平布局中放置了两个按钮.然后我将此布局放置在包含水平和垂直间隔的网格布局中.我已将网格布局 layoutSize 属性修改为 SetMaximumSize.

I have placed two Push Buttons inside a Horizontal Layout. I then placed this layout inside a Grid Layout, which contains a Horizontal and Vertical Spacer. I have modified the Grid Layout layoutSize property to SetMaximumSize.

我做错了什么,才能将按钮固定在右下角?

What am I doing incorrectly, so that I can get my buttons to be anchored to the bottom right?

推荐答案

这里几乎所有东西都应有尽有,但是当您第一次开始使用 Qt Designer 时,您可能忽略了一些很容易错过的东西.

You have almost everything just right here, but you probably overlooked something that is really easy to miss when you first start using Qt Designer.

您的网格布局位于具有固定大小和位置的小部件内.它也需要由布局管理.如果您查看右上角的 Object Inspector(包含您的层次结构),您可能会看到带有红色图标的顶级小部件.这表明它不包含布局.您有两个选项可以解决此问题...

Your grid layout is sitting inside your widget with a fixed size and position. It too needs to be managed by a layout. If you take a look at the Object Inspector on the top right (that contains your hierarchy) you will probably see your top level widget with a red icon. This indicates that it contains no layout. You have two options to fix this...

  1. 将您现有的网格布局放入另一个主布局(如垂直布局)中.您只需右键单击对象检查器中的顶级小部件 -> 布局 -> [选择主要布局类型].
  2. 让您的网格成为主要布局.要做到这一点,您需要删除网格布局,并让您的子项目完全按照您在该图片中的方式进行排列.然后按照上一个选项,右键单击顶级小部件(或空白背景)并选择布局 -> 网格.这会将您的小部件以最佳视觉效果弹出到网格中(然后您可以根据需要进行修复),并且您的网格将成为顶级布局.

这篇关于QT - 在右下角放置按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆