删除QWidget周围的额外间距 [英] Removing extra spacing around QWidget

查看:123
本文介绍了删除QWidget周围的额外间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何清除QWidget周围的额外间距?

How to remove extra spacing around QWidget?

这里有一个简单的例子。窗口小部件的空间是灰色的;您会看到,它的内容(图片,文字和按钮)周围有一些空间(约0.3-0.4厘米)。

Here's the simple example. The widget's space is grey; you see, there's some space (about 0.3-0.4 cm) around the content of it (image, text and button).

setAutoFillBackground(true);
QPalette pal(palette());
pal.setColor(QPalette::Background, QColor("#e5e5e5"));
setPalette(pal);

这里是内容(通过运行 setStyleSheet(background-color:red);

Here's the content (highlighted by running setStyleSheet( "background-color: red"); for the whole widget.

通过移除额外的间距,我理解去除内容周围约0.2-0.3厘米的灰色空间,留下约0.05-0.1厘米。

By 'removing extra spacing' I understand removing about 0.2-0.3 cm of grey space around content and leaving about 0.05-0.1 cm.

推荐答案

使用方法 setContentsMargins()

这篇关于删除QWidget周围的额外间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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