我在 QT 设计器应用程序中的标签非常合适且井井有条。但是,一旦我将 UI 文件转换为 python 并运行它,我会在标签中得到完全不同的结果。这是一个演示:
QT Designer 拖放应用程序:
https://i.stack.imgur.com/eMmwe.png
转换为python文件:
https://i.stack.imgur.com/HOS74.png
这是python代码:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'menu.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(736, 670)
MainWindow.setMaximumSize(QtCore.QSize(16777215, 16777215))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.frame = QtWidgets.QFrame(self.centralwidget)
self.frame.setStyleSheet("background-color: rgb(85, 0, 127);")
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.verticalLayout = QtWidgets.QVBoxLayout(self.frame)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.frame_2 = QtWidgets.QFrame(self.frame)
self.frame_2.setMaximumSize(QtCore.QSize(16777215, 120))
self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_2.setObjectName("frame_2")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.frame_2)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.lineEdit = QtWidgets.QLineEdit(self.frame_2)
self.lineEdit.setObjectName("lineEdit")
self.verticalLayout_2.addWidget(self.lineEdit)
self.lineEdit_2 = QtWidgets.QLineEdit(self.frame_2)
self.lineEdit_2.setObjectName("lineEdit_2")
self.verticalLayout_2.addWidget(self.lineEdit_2)
self.verticalLayout.addWidget(self.frame_2)
self.frame_3 = QtWidgets.QFrame(self.frame)
self.frame_3.setMaximumSize(QtCore.QSize(16777215, 800))
self.frame_3.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_3.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_3.setObjectName("frame_3")
self.gridLayout_2 = QtWidgets.QGridLayout(self.frame_3)
self.gridLayout_2.setObjectName("gridLayout_2")
self.widget = QtWidgets.QWidget(self.frame_3)
self.widget.setMaximumSize(QtCore.QSize(400, 100))
self.widget.setObjectName("widget")
self.gridLayout_3 = QtWidgets.QGridLayout(self.widget)
self.gridLayout_3.setObjectName("gridLayout_3")
self.pushButton = QtWidgets.QPushButton(self.widget)
self.pushButton.setMinimumSize(QtCore.QSize(0, 40))
self.pushButton.setMaximumSize(QtCore.QSize(16777215, 16777215))
font = QtGui.QFont()
font.setFamily("Lucida Sans")
font.setPointSize(15)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
font.setStrikeOut(False)
self.pushButton.setFont(font)
self.pushButton.setAutoFillBackground(False)
self.pushButton.setStyleSheet("QPushButton {\n"
"background-color: rgb(0, 0, 0);\n"
"color: rgb(255, 255, 255);\n"
"}\n"
"QPushButton:focus { outline: none; }")
self.pushButton.setAutoDefault(True)
self.pushButton.setDefault(True)
self.pushButton.setFlat(False)
self.pushButton.setObjectName("pushButton")
self.gridLayout_3.addWidget(self.pushButton, 0, 0, 1, 1)
self.pushButton_2 = QtWidgets.QPushButton(self.widget)
self.pushButton_2.setMinimumSize(QtCore.QSize(0, 40))
self.pushButton_2.setMaximumSize(QtCore.QSize(16777215, 16777215))
font = QtGui.QFont()
font.setFamily("Lucida Sans")
font.setPointSize(15)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
font.setStrikeOut(False)
self.pushButton_2.setFont(font)
self.pushButton_2.setAutoFillBackground(False)
self.pushButton_2.setStyleSheet("QPushButton {\n"
"background-color: rgb(0, 0, 0);\n"
"color: rgb(255, 255, 255);\n"
"}\n"
"QPushButton:focus { outline: none; }")
self.pushButton_2.setAutoDefault(True)
self.pushButton_2.setDefault(True)
self.pushButton_2.setFlat(False)
self.pushButton_2.setObjectName("pushButton_2")
self.gridLayout_3.addWidget(self.pushButton_2, 0, 1, 1, 1)
self.pushButton_3 = QtWidgets.QPushButton(self.widget)
self.pushButton_3.setMinimumSize(QtCore.QSize(0, 40))
self.pushButton_3.setMaximumSize(QtCore.QSize(16777215, 16777215))
font = QtGui.QFont()
font.setFamily("Lucida Sans")
font.setPointSize(15)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
font.setStrikeOut(False)
self.pushButton_3.setFont(font)
self.pushButton_3.setAutoFillBackground(False)
self.pushButton_3.setStyleSheet("QPushButton {\n"
"background-color: rgb(0, 0, 0);\n"
"color: rgb(255, 255, 255);\n"
"}\n"
"QPushButton:focus { outline: none; }")
self.pushButton_3.setAutoDefault(True)
self.pushButton_3.setDefault(True)
self.pushButton_3.setFlat(False)
self.pushButton_3.setObjectName("pushButton_3")
self.gridLayout_3.addWidget(self.pushButton_3, 1, 0, 1, 1)
self.pushButton_4 = QtWidgets.QPushButton(self.widget)
self.pushButton_4.setMinimumSize(QtCore.QSize(0, 40))
self.pushButton_4.setMaximumSize(QtCore.QSize(16777215, 16777215))
font = QtGui.QFont()
font.setFamily("Lucida Sans")
font.setPointSize(15)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
font.setStrikeOut(False)
self.pushButton_4.setFont(font)
self.pushButton_4.setAutoFillBackground(False)
self.pushButton_4.setStyleSheet("QPushButton {\n"
"background-color: rgb(0, 0, 0);\n"
"color: rgb(255, 255, 255);\n"
"}\n"
"QPushButton:focus { outline: none; }")
self.pushButton_4.setAutoDefault(True)
self.pushButton_4.setDefault(True)
self.pushButton_4.setFlat(False)
self.pushButton_4.setObjectName("pushButton_4")
self.gridLayout_3.addWidget(self.pushButton_4, 1, 1, 1, 1)
self.gridLayout_2.addWidget(self.widget, 0, 0, 1, 1)
self.widget_2 = QtWidgets.QWidget(self.frame_3)
self.widget_2.setObjectName("widget_2")
self.gridLayout_2.addWidget(self.widget_2, 1, 0, 1, 1)
self.verticalLayout.addWidget(self.frame_3)
self.frame_4 = QtWidgets.QFrame(self.frame)
self.frame_4.setMaximumSize(QtCore.QSize(16777215, 50))
self.frame_4.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_4.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_4.setObjectName("frame_4")
self.verticalLayout.addWidget(self.frame_4)
self.gridLayout.addWidget(self.frame, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "Ban Members"))
self.pushButton_2.setText(_translate("MainWindow", "Delete Channels"))
self.pushButton_3.setText(_translate("MainWindow", "Spam Channels"))
self.pushButton_4.setText(_translate("MainWindow", "Nuke"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
有谁知道解决这个问题的解决方案?