QPushButton更改相同布局中其他小部件的边距 [英] QPushButton changes margins on other widgets in the same layout

查看:300
本文介绍了QPushButton更改相同布局中其他小部件的边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的布局,其中包含以下结构的小部件和布局:

I have a big layout that contains widgets and layouts of the following structure:

QVBoxLayout
  QTableView
  QPushButton

我将布局的边距,内边距和间距设置为0.在Mac OS X上呈现的方式是,按钮未填充其所有空间.相反,它周围有一些填充.神奇的是,布局似乎知道这一点,并确保表格视图的宽度与按钮的宽度完全一样:

I set the margins, padding, and spacing on the layout to 0. The way this renders on Mac OS X, the button doesn't fill all of its space. Instead, there is some padding around it. Magically, the layout seems to know this, and makes sure the table view is exactly as wide as the button is wide:

当我删除按钮时,表格视图将返回其完整宽度:

When I remove the button, the table view returns to its full width:

如何更改它,以使按钮以及表格视图变得与布局一样宽?

How can I change it so the button, as well as the table view, become as wide as the layout?

我玩过样式表的填充和边距,虽然可以使用它们来使按钮变宽,但树视图周围的多余填充仍然保留.到目前为止,我唯一的解决方案是将按钮包装在另一个小部件中,然后通过样式表将其边距和内边距设置为0,但随后我失去了圆角外观.

I've played with stylesheet's padding and margin, and while I can use those to make the button wider, the extra padding around the tree view remains. The only solution I have so far is to wrap the button in another widget, and then set its margin and padding to 0 via stylesheet, but then I lose the rounded look.

推荐答案

您必须将布局边距设置为0,而不是QPushButton的边距.

you have to set layout margins to 0, not QPushButton's margins.

看看.这是设计师的外观:

Take a look. this is designer look&feel:

这是QWidget的布局属性:

This is QWidget's layout properties:

这是最终的小部件:

这篇关于QPushButton更改相同布局中其他小部件的边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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