Qt Stylesheets - how to remove dead space

纵饮孤独 提交于 2019-12-25 02:31:44

问题


I am creating a simple plotting application using PySide and have a problem with loads of dead space.

How can I remove all this extra padding using stylesheets (preferably) or programmatically? I've tried setting margins and padding on QFrame to 0, but with little effect.

I'm using layouts for positioning and my widgets inherit from QFrame and generally contain other widgets such as QTabWidget, QListWidget etc..

(I have avoided the use of QWidget as I believe this is not fully supported by Qt Stylesheets)

Below is a screenshot of my app, with red lines pointing out my problematic dead space (The bottom red line is a bit too long - there is a statusbar)

Any ideas?


回答1:


If you color the background of your widgets you see that no value for property margin or padding will change the spacing in between and the margin. This is controlled by the layout. Therefore in your layout set:

layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)

and all empty spaces should be gone. Unfortunately this can only be done programmatically and not by stylesheets. See also comments in Qt set contentsMargins from stylesheet and Qt remove margins



来源:https://stackoverflow.com/questions/24867987/qt-stylesheets-how-to-remove-dead-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!