L
L
LowLevel2019-04-22 20:58:55
Python
LowLevel, 2019-04-22 20:58:55

Added a widget, but it didn't show up when I started the program (PyQt5). What have I done wrong?

I created a class that calls an additional window. When you add widgets to it and then compile them, they are not displayed. I can't understand the reason.
I started learning PyQt a month ago.
This is the empty window I see
5cbe005968f80030383188.jpeg

import sys
from MainWindow import *
from PyQt5 import QtCore, QtGui, QtWidgets

class Cost_Actives(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent, QtCore.Qt.Window)
        self.build()
    def build(self):
        self.qle = QtWidgets.QTextEdit()
        
             
class MyWin(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.ui= Ui_MainWindow()
        self.ui.setupUi(self)
    
        self.ui.pushButton.clicked.connect(self.CostA)

    def CostA(self):
        self.secondWin = Cost_Actives(self)
        self.secondWin.show()
    
if __name__=="__main__":
    app = QtWidgets.QApplication(sys.argv)
    myapp = MyWin()
    myapp.show()
    sys.exit(app.exec_())

Thank you for attention!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bbkmzzzz, 2019-04-23
@LowLevel

Did you specify what and where to draw?

def build(self):
        # self.qle = QtWidgets.QTextEdit()  # Создание атрибута класса и запись туда QTextEdit (и все)
        self.qle = QtWidgets.QTextEdit(self)  # передайте родителя!

You can do the same as with the main window. Create ui -> py
class Cost_Actives(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent, QtCore.Qt.Window)
        self.ui = Ui_Form()
        self.ui.setupUi(self)

PS Do not use import via *, import only what you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question