Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

pyqt5 qtdesigner设计好的UI界面 增加底部布局之后全部控件集合在了左上角

没有加底部布局之前如图:
image.png
加了底部布局之后:
image.png

代码如图:
main.js封装:

import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
from Ui_MainWindow import *

class Demo(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super(Demo, self).__init__()
        # 将UI界面布局到Demo上;
        self.setupUi(self)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    demo = Demo()
    demo.show()
    sys.exit(app.exec_())

部分UI转换成的py代码:

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(942, 666)
        # 定义的底层栅格布局
        self.gridLayout_main = QtWidgets.QGridLayout(MainWindow)
        self.gridLayout_main.setContentsMargins(15, -1, -1, -1)
        self.gridLayout_main.setVerticalSpacing(20)
        self.gridLayout_main.setObjectName("gridLayout_main")
        # 子布局之一
        self.gridLayout_3 = QtWidgets.QGridLayout()
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.verticalLayout_4 = QtWidgets.QVBoxLayout()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

在qtdesigner 可以拉开吧


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...