Unsolved QGridLayout I'm not able to add new widget
-
I'm new to Qt5, I have a simple QGridLayout layout mask . I want to create a windows with the widget resize with resize of window
this is the code
import sys from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import QFileDialog ,QVBoxLayout,QGroupBox,QGridLayout class MainWindow(QtWidgets.QMainWindow, QtWidgets.QFileDialog, QtWidgets.QLineEdit): def __init__(self): super().__init__() self.title = "Calcolo Hash" self.top = 100 self.left = 100 self.width = 800 self.height = 330 self.InitWindow() def InitWindow(self): self.setWindowIcon(QtGui.QIcon("icona_aprie.png")) self.setWindowTitle(self.title) self.setGeometry(self.top, self.left, self.width, self.height) self.creamaschera() self.show() def creamaschera(self): print ("creazione maschera") layout = QtWidgets.QGridLayout() self.txtcartella = QtWidgets.QLineEdit() self.lblprova = QtWidgets.QLabel("Please enter new name:") # self.txtcartella.setGeometry(QtCore.QRect(10, 10, 301, 20)) # self.txtcartella.setObjectName("txtcartella") layout.addWidget(self.lblprova,0,0) layout.addWidget(self.txtcartella,0,1) self.setLayout(layout) # self.horizontalGroupBox.setLayout(layout) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) w = MainWindow() #w.show() sys.exit(app.exec_())
but when I run the mask is empy. I make the base with Qt5 designer and convert it to python. I want to refactor the class in a best workout. Where is the error?
-
@ossarotte QMainWindow has central widget, you should use that one to set layout with other widgets. See https://doc.qt.io/qt-5/qmainwindow.html#centralWidget