I am new to Qt Designer and PyCharm and when I want to make a small program for practice, I have encountered a layout problem.
I use Qt Designer to design the layout and use PyUIC as an external tool to convert my login.ui into login.py.
I use Form Layout as my layout and put two pairs of labels and lineEdits.
Before running my program, I press the preview button to check my layout first, every thing looks as expected:
But when I run my program in PyCharm, it looks weird and I don't know why:
I have two .py files: login.py and mainn.py
login.py:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(473, 436)
self.formLayout = QtWidgets.QFormLayout(Form)
self.formLayout.setObjectName("formLayout")
self.label = QtWidgets.QLabel(Form)
self.label.setObjectName("label")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole,
self.label)
self.lineEdit = QtWidgets.QLineEdit(Form)
self.lineEdit.setObjectName("lineEdit")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole,
self.lineEdit)
self.label_2 = QtWidgets.QLabel(Form)
self.label_2.setObjectName("label_2")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole,
self.label_2)
self.lineEdit_2 = QtWidgets.QLineEdit(Form)
self.lineEdit_2.setObjectName("lineEdit_2")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole,
self.lineEdit_2)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.label.setText(_translate("Form", "Label 1"))
self.label_2.setText(_translate("Form", "Label 2"))
mainn.py:
import sys
import login
from PyQt5.QtWidgets import QApplication, QMainWindow
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = login.Ui_Form()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
By the my I am running on a High-DPI laptop, I'm not sure if this is one of the reason. Any ideas? Thanks!