Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QGridLayout I'm not able to add new widget

    General and Desktop
    2
    2
    84
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      ossarotte last edited by

      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?

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @ossarotte last edited by

        @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

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • First post
          Last post