pyqt: how to put a border frame around a widget

那年仲夏 提交于 2019-12-04 20:58:32

Put your QWidget inside another QWidget with its background set to the same colour.

You can then use the layout of the parent QWidget to adjust the width of the margin on each side (this can all be done within Qt Designer).

EDIT

Here are the steps to take in Qt Designer to achieve this:

  1. Select the frame widget containing the text widget and break its layout.
  2. Add a new QWidget to the frame widget (you could name it "borderWidget").
  3. Set the background colour of the border widget using the styleSheet property in the Property Editor: e.g. background-color: white. (nb: it might help if you temporarily set this to a contrasting colour so you can more easily see what's going on).
  4. Drag and drop the text widget onto the border widget.
  5. Select the border widget and set it's layout (e.g. "Lay Out in a Grid").
  6. Select the frame widget and set it's layout (e.g. "Lay Out in a Grid").
  7. Select the border widget. Go to the Layout section in the Property Editor. There you will see properties like layoutTopMargin, layoutLeftMargin, etc which can be used to adjust the size of the border.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!