Size of verticalLayout is different in Qt Designer and PyQt program

后端 未结 2 679
挽巷
挽巷 2020-12-07 04:33

In Qt Designer 5.9 the verticalLayout in test.ui had a certain distance to the edge of the window, but after loading test.ui with PyQt

2条回答
  •  暖寄归人
    2020-12-07 05:12

    Based off @eyllanesc's answer, here's a monkey patch that fixed the issue for me.

    This solution works because the only code inside PyQt5 that cares about the WidgetStack.topIsLayoutWidget attribute is the UIParser.createLayout() method, and it only uses that attribute to decide whether to set the default margins to zero.

    from PyQt5.uic import uiparser
    
    uiparser.WidgetStack.topIsLayoutWidget = lambda self: False
    

提交回复
热议问题