0

I made a pyqt GUI in QT Designer 4.8.5. I converted the .gui file to .py and wrote some code to run the application. However, the outcome is not what I wished for.

Expected (as shown when running preview in QT Designer): enter image description here

Result when running the converted .py: enter image description here

As you can see, the content of the centralwidget is pulled (stretched) behind the title bar. The text in the labels is also a bit blurry.

It used to work without any problems, but I accidentaly upgraded pyqt (was trying something) and since then, it's broken. The code of my converted .py file is below.

Anybody knows what's changed in pyqt and how to fix it? The gui code is written in the file UFA_gui.py:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'UFA_UIv0_1.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 635)
        MainWindow.setMinimumSize(QtCore.QSize(800, 600))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/icon/IconUH.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.centralwidget.sizePolicy().hasHeightForWidth())
        self.centralwidget.setSizePolicy(sizePolicy)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout_2.setContentsMargins(9, -1, -1, -1)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setObjectName("verticalLayout")
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.loadButton = QtWidgets.QPushButton(self.centralwidget)
        self.loadButton.setObjectName("loadButton")
        self.horizontalLayout.addWidget(self.loadButton)
        self.updateButton = QtWidgets.QPushButton(self.centralwidget)
        self.updateButton.setEnabled(False)
        self.updateButton.setObjectName("updateButton")
        self.horizontalLayout.addWidget(self.updateButton)
        self.saveButton = QtWidgets.QPushButton(self.centralwidget)
        self.saveButton.setEnabled(False)
        self.saveButton.setObjectName("saveButton")
        self.horizontalLayout.addWidget(self.saveButton)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.checkBox_wintertijd = QtWidgets.QCheckBox(self.centralwidget)
        self.checkBox_wintertijd.setEnabled(False)
        self.checkBox_wintertijd.setObjectName("checkBox_wintertijd")
        self.verticalLayout.addWidget(self.checkBox_wintertijd)
        self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
        self.textEdit.setObjectName("textEdit")
        self.verticalLayout.addWidget(self.textEdit)
        self.gridLayout_2.addLayout(self.verticalLayout, 0, 0, 1, 1)
        self.verticalLayout_2 = QtWidgets.QVBoxLayout()
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setContentsMargins(-1, -1, 0, -1)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setMinimumSize(QtCore.QSize(0, 23))
        self.label_2.setMaximumSize(QtCore.QSize(65, 23))
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_2.addWidget(self.label_2)
        self.comboBox = QtWidgets.QComboBox(self.centralwidget)
        self.comboBox.setEnabled(False)
        self.comboBox.setMinimumSize(QtCore.QSize(150, 23))
        self.comboBox.setMaximumSize(QtCore.QSize(100, 23))
        self.comboBox.setObjectName("comboBox")
        self.horizontalLayout_2.addWidget(self.comboBox)
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setObjectName("label_3")
        self.horizontalLayout_2.addWidget(self.label_3)
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_2.addItem(spacerItem)
        self.verticalLayout_2.addLayout(self.horizontalLayout_2)
        spacerItem1 = QtWidgets.QSpacerItem(20, 17, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.verticalLayout_2.addItem(spacerItem1)
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setObjectName("label")
        self.verticalLayout_2.addWidget(self.label)
        self.webView = QtWebEngineWidgets.QWebEngineView(self.centralwidget)
        self.webView.setUrl(QtCore.QUrl("about:blank"))
        self.webView.setObjectName("webView")
        self.verticalLayout_2.addWidget(self.webView)
        self.verticalLayout_2.setStretch(2, 6)
        self.verticalLayout_2.setStretch(3, 3)
        self.gridLayout_2.addLayout(self.verticalLayout_2, 0, 1, 1, 1)
        self.gridLayout_2.setColumnStretch(0, 1)
        self.gridLayout_2.setColumnStretch(1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Mainwindow"))
        self.loadButton.setText(_translate("MainWindow", "Open "))
        self.updateButton.setText(_translate("MainWindow", "Update "))
        self.saveButton.setText(_translate("MainWindow", "Exporteer "))
        self.checkBox_wintertijd.setText(_translate("MainWindow", "Gemeten in wintertijd"))
        self.label_2.setText(_translate("MainWindow", "KNMI "))
        self.label_3.setText(_translate("MainWindow", "Temperatuur "))
        self.label.setText(_translate("MainWindow", "TextLabel"))

from PyQt5 import QtWebEngineWidgets

The code start the application:

import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5 import QtWidgets
from UFA_gui import Ui_MainWindow

class MyFirstGuiProgram(Ui_MainWindow):

    def __init__(self, MainWindow):

        Ui_MainWindow.__init__(self)
        self.setupUi(MainWindow)

        self.loadButton.clicked.connect(self.load_file)

    def load_file(self):
        self.label.setText("click")

        self.updateButton.setEnabled(True)
        self.saveButton.setEnabled(True)

if __name__ == '__main__':

    app = QApplication(sys.argv)

    MainWindow = QtWidgets.QMainWindow()

    prog = MyFirstGuiProgram(MainWindow)

    MainWindow.show()
    sys.exit(app.exec_())
Coen Smits
  • 45
  • 6
  • 1
    I cannot reproduce this (on linux, using python 3.6.3, qt 5.9.3, pyqt 5.9.2). Please show the missing code. – ekhumoro Dec 08 '17 at 16:48
  • Of course, that'd be handy. Sorry I didn't add it yet. I added it now. It's a simplification of my code, but with this I reproduce the problem. I'm using windows 10, python 3.6.3 and pyqt 5.9.2 – Coen Smits Dec 08 '17 at 16:53
  • @CoenSmits In Linux is not the problem because it works correctly, I recommend you try another machine. Similar problems observed by problems of versions of the video card in windows when using QtWebEngineWidgets, if you look in SO you will see that there are 2 post of that type and the solution was to install the correct version of the driver. – eyllanesc Dec 08 '17 at 16:56
  • That might actually be it: The problems started when I updated pyqt and also had to replace the QWebKit with QtWebEngineWidgets, because QWebKit was deprecated. I never thought that this widget was the cause of this gui problem.Thanks! – Coen Smits Dec 08 '17 at 16:59
  • Updating drivers indeed fixed the problem. Thanks for the help guys, I really thought it was something in the code and was already stuck on it for quite some time. – Coen Smits Dec 08 '17 at 17:08

0 Answers0