I have a Dialog
with a unique Wigdet
that occupies the entire window. In this case it is a QTextEdit
and is created with Qt Designer
.
This is the file in Python
:
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_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(400, 300)
self.gridLayout = QtGui.QGridLayout(Dialog)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.textEdit = QtGui.QTextEdit(Dialog)
self.textEdit.setObjectName(_fromUtf8("textEdit"))
self.gridLayout.addWidget(self.textEdit, 0, 0, 1, 1)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
However, when executing the code that you throw from Dialog
the Widget
is not resized.
import sys
from qtdesigner.dialog_reacciones_rsa import *
class Window(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
self.ui.textEdit.setText('Hola\nAdios')
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
myapp = Window()
myapp.show()
sys.exit(app.exec_())
Edited on 06.21.2018
I modify the code of Dialog
according to FJSevilla's comment:
...
class Window(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
...