Answer the question
In order to leave comments, you need to log in
How to properly generate forms in PyQt?
Hello!
I use QtDesigner to draw GUI. Using the pyuic utility, I distill this into Python code. In general, everything is as usual. But after converting to python, everything breaks on the form.
Here is the form in QtDesigner.
And here is the form after the pyuic transformation:
The size of the window has changed, and the menu has disappeared behind the arrow.
Here is the code for the .ui file
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPlainTextEdit" name="txbx_text">
<property name="geometry">
<rect>
<x>3</x>
<y>0</y>
<width>391</width>
<height>251</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="plainText">
<string/>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menu">
<property name="title">
<string>Файл</string>
</property>
<addaction name="mnu_open"/>
</widget>
<widget class="QMenu" name="menu_2">
<property name="title">
<string>Лог</string>
</property>
<addaction name="mnu_export"/>
<addaction name="mnu_add_log"/>
<addaction name="mnu_view"/>
</widget>
<addaction name="menu"/>
<addaction name="menu_2"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="mnu_open">
<property name="text">
<string>Открыть</string>
</property>
</action>
<action name="mnu_export">
<property name="text">
<string>Экспорт</string>
</property>
</action>
<action name="mnu_add_log">
<property name="text">
<string>Добавить в лог</string>
</property>
</action>
<action name="mnu_view">
<property name="text">
<string>Просмотр</string>
</property>
</action>
<action name="actionDsfsdf">
<property name="text">
<string>dsfsdf</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created: Tue Apr 19 23:18:32 2016
# by: PyQt4 UI code generator 4.11.2
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(400, 300)
self.centralWidget = QtGui.QWidget(MainWindow)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
self.txbx_text = QtGui.QPlainTextEdit(self.centralWidget)
self.txbx_text.setGeometry(QtCore.QRect(3, 0, 391, 251))
self.txbx_text.setReadOnly(True)
self.txbx_text.setPlainText(_fromUtf8(""))
self.txbx_text.setObjectName(_fromUtf8("txbx_text"))
# MainWindow.setCentralWidget(self.centralWidget)
self.menuBar = QtGui.QMenuBar(MainWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 400, 21))
self.menuBar.setObjectName(_fromUtf8("menuBar"))
self.menu = QtGui.QMenu(self.menuBar)
self.menu.setObjectName(_fromUtf8("menu"))
self.menu_2 = QtGui.QMenu(self.menuBar)
self.menu_2.setObjectName(_fromUtf8("menu_2"))
# MainWindow.setMenuBar(self.menuBar)
self.statusBar = QtGui.QStatusBar(MainWindow)
self.statusBar.setObjectName(_fromUtf8("statusBar"))
# MainWindow.setStatusBar(self.statusBar)
self.mnu_open = QtGui.QAction(MainWindow)
self.mnu_open.setObjectName(_fromUtf8("mnu_open"))
self.mnu_export = QtGui.QAction(MainWindow)
self.mnu_export.setObjectName(_fromUtf8("mnu_export"))
self.mnu_add_log = QtGui.QAction(MainWindow)
self.mnu_add_log.setObjectName(_fromUtf8("mnu_add_log"))
self.mnu_view = QtGui.QAction(MainWindow)
self.mnu_view.setObjectName(_fromUtf8("mnu_view"))
self.actionDsfsdf = QtGui.QAction(MainWindow)
self.actionDsfsdf.setObjectName(_fromUtf8("actionDsfsdf"))
self.menu.addAction(self.mnu_open)
self.menu_2.addAction(self.mnu_export)
self.menu_2.addAction(self.mnu_add_log)
self.menu_2.addAction(self.mnu_view)
self.menuBar.addAction(self.menu.menuAction())
self.menuBar.addAction(self.menu_2.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.menu.setTitle(_translate("MainWindow", "Файл", None))
self.menu_2.setTitle(_translate("MainWindow", "Лог", None))
self.mnu_open.setText(_translate("MainWindow", "Открыть", None))
self.mnu_export.setText(_translate("MainWindow", "Экспорт", None))
self.mnu_add_log.setText(_translate("MainWindow", "Добавить в лог", None))
self.mnu_view.setText(_translate("MainWindow", "Просмотр", None))
self.actionDsfsdf.setText(_translate("MainWindow", "dsfsdf", None))
Answer the question
In order to leave comments, you need to log in
In order not to dig, it’s better to write yourself ..
if you decide, here is a link of good lessons, though on PyQt5
python-3.ru/page/into-pyqt5
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question