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. Basic QT5 Help
Forum Updated to NodeBB v4.3 + New Features

Basic QT5 Help

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 3.2k Views
  • 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
    Olivermadsen
    wrote on last edited by
    #1

    Can someone please help me understand why this code isn't running? I am very new to QT5. I get the following error messages (I am running in pycharm):
    Traceback (most recent call last):
    File "/Users/oliverm/PycharmProjects/Plural-Sight /Basic Structure/1.py", line 26, in <module>
    dialog = HelloWorld()
    File "/Users/oliverm/PycharmProjects/Plural-Sight /Basic Structure/1.py", line 18, in init
    layout.addWidget(label)
    TypeError: addWidget(self, QWidget, stretch: int = 0, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = 0): first argument of unbound method must have type 'QBoxLayout'
    Code:
    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
    from PyQt5.Qt import *
    import sys

    class HelloWorld(QDialog):
    def init(self):
    QDialog.init(self)

        layout = QVBoxLayout
    
        label = QLabel
        line_edit = QLineEdit()
        button = QPushButton("Close")
    
        layout.addWidget(label)
        layout.addWidget(line_edit)
        layout.addWidget(button)
    
        self.setLayout(layout)
    

    app = QApplication(sys.argv)
    dialog = HelloWorld()
    dialog.show()
    app.exec_()

    JonBJ 1 Reply Last reply
    0
    • O Olivermadsen

      Can someone please help me understand why this code isn't running? I am very new to QT5. I get the following error messages (I am running in pycharm):
      Traceback (most recent call last):
      File "/Users/oliverm/PycharmProjects/Plural-Sight /Basic Structure/1.py", line 26, in <module>
      dialog = HelloWorld()
      File "/Users/oliverm/PycharmProjects/Plural-Sight /Basic Structure/1.py", line 18, in init
      layout.addWidget(label)
      TypeError: addWidget(self, QWidget, stretch: int = 0, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = 0): first argument of unbound method must have type 'QBoxLayout'
      Code:
      from PyQt5.QtCore import *
      from PyQt5.QtGui import *
      from PyQt5.QtWidgets import *
      from PyQt5.Qt import *
      import sys

      class HelloWorld(QDialog):
      def init(self):
      QDialog.init(self)

          layout = QVBoxLayout
      
          label = QLabel
          line_edit = QLineEdit()
          button = QPushButton("Close")
      
          layout.addWidget(label)
          layout.addWidget(line_edit)
          layout.addWidget(button)
      
          self.setLayout(layout)
      

      app = QApplication(sys.argv)
      dialog = HelloWorld()
      dialog.show()
      app.exec_()

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Olivermadsen

          layout = QVBoxLayout
      
          label = QLabel
      

      I use PyQt/Python. Unless I am wildly mistaken, you can't write those, this is not C++! I would assume those set the label to the function, they do not call the function.

          layout = QVBoxLayout()
      
          label = QLabel()
      

      Does that remove your errors? You cannot lazily omit the () like you can in C++ ( layout = new QVBoxLayout, which I don't much like anyway), put them in always.

      O 1 Reply Last reply
      3
      • JonBJ JonB

        @Olivermadsen

            layout = QVBoxLayout
        
            label = QLabel
        

        I use PyQt/Python. Unless I am wildly mistaken, you can't write those, this is not C++! I would assume those set the label to the function, they do not call the function.

            layout = QVBoxLayout()
        
            label = QLabel()
        

        Does that remove your errors? You cannot lazily omit the () like you can in C++ ( layout = new QVBoxLayout, which I don't much like anyway), put them in always.

        O Offline
        O Offline
        Olivermadsen
        wrote on last edited by
        #3

        @JonB Thanks Jon! works perfectly.

        1 Reply Last reply
        1

        • Login

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