Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGridLayout I'm not able to add new widget
Forum Updated to NodeBB v4.3 + New Features

QGridLayout I'm not able to add new widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 208 Views 1 Watching
  • 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 Offline
    O Offline
    ossarotte
    wrote on last edited by
    #1

    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?

    jsulmJ 1 Reply Last reply
    0
    • O ossarotte

      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?

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved