0

UI file previewed in Qt designer The tag size and tag position in the page are different from those displayed in the UI file loaded in Python, and the page tags in Qt Designer can be fully previewed, but not completely displayed in Python, what is the reason, how to solve these situations, sincerely solve

The preview page in Qt Designer looks like this enter image description here enter image description here

But the page loaded in pycharm looks like this enter image description here enter image description here

Why this discrepancy?

The code in pycharm is as follows:

import sys
from PyQt5.uic import loadUi
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QApplication, QWidget, QStackedWidget, QVBoxLayout


class WelcomeScreen(QDialog):
    def __init__(self):
        super(WelcomeScreen, self).__init__()
        loadUi("welcome.ui", self)
        self.login1.clicked.connect(self.gotologin)

    def gotologin(self):
        login = LoginScreen()
        widget.addWidget(login)
        widget.setCurrentIndex(widget.currentIndex() + 1)


class LoginScreen(QDialog):
    def __init__(self):
        super(LoginScreen, self).__init__()
        loadUi("login.ui", self)
        self.password.setEchoMode(QtWidgets.QLineEdit.Password)


app = QApplication(sys.argv)
welcome = WelcomeScreen()
widget = QStackedWidget()
widget.addWidget(welcome)
widget.setFixedHeight(504)
widget.setFixedWidth(718)
widget.show()
try:
    sys.exit(app.exec_())
except:
    print("exiting")
  • That's caused by the fact that you're not using [layout managers](https://doc.qt.io/qt-5/designer-layouts.html), which is one of the *many* issues of that youtube tutorial you're probably following. I strongly suggest you to completely disregard it, and look for other resources (start from [these](https://wiki.python.org/moin/PyQt/Tutorials), for example). – musicamante Aug 30 '23 at 15:41

0 Answers0