Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. How to move class method out of gui modul
Forum Updated to NodeBB v4.3 + New Features

How to move class method out of gui modul

Scheduled Pinned Locked Moved Unsolved Language Bindings
python
35 Posts 4 Posters 15.4k Views 2 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.
  • SGaistS SGaist

    So you know how to split your code in several logical modules/files and import them to use them ?

    C Offline
    C Offline
    California
    wrote on last edited by
    #26

    @SGaist No probles with importing functions, more troubles with classes, specially with everything related to gui.
    My project is unique and it's not comercial.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      California
      wrote on last edited by
      #27

      Smal change in function makes script running without an error but only "Unchecked" is printed out when radiobutton is checked or it is unchecked. How to fix this to have correct respond?

      # python 2.7.9
      from PyQt4 import QtCore, QtGui
      #from gui_1 import Ui_Form
      
      
      def print_situation(*args):
          radioButton = QtGui.QRadioButton()
          if radioButton.isChecked():
              print "Checked"
          else:
              print "Unchecked"
      
      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #28

        Importing functions or classes is exactly the same process.

        The thing that you seem to want to do is take apart class functions

        Take a look at the 3rd example from the PyQt 5 designer introduction documentation.

        Basically, you have your generated file from pyuic5, then you create your own class that will use the generated code. Finally a main.py where you will instantiate your custom widget(s) and start the application.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #29

          Hi
          Wont

          def print_situation(*args):
              radioButton = QtGui.QRadioButton()
              if radioButton.isChecked():
                  print "Checked"
              else:
                  print "Unchecked"
          

          radioButton = QtGui.QRadioButton()
          create a new QRadioButton

          Each time and its unchecked by default.

          Hence it always says "Unchecked" ?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            California
            wrote on last edited by
            #30

            @mrjj you are right I suppose

            @SGaist I tried to follow your point but ...
            code:

            # python 2.7.9
            from PyQt4 import QtCore, QtGui
            from PyQt4.QtGui import QCheckBox
            #from gui_5 import Ui_Form
            
            
            class My_app(QCheckBox):
                def __init__(self):
                    super(My_app, self).__init__()
                    # Set up the user interface from Designer.
                    self.setupUi(self)
                    self.checkBox = QtGui.QCheckBox(self)
                    # Connect up the buttons.
                    self.checkBox.clicked.connect(self.accept)
            
                def print_situation(self, *args):
                    if self.checkBox.checkState() == QtCore.Qt.Checked:
                        print "Checked"
                    else:
                        print "Unchecked"
            

            error:

            Traceback (most recent call last):
              File "/home/pi/Desktop/Qt4/Project/01/Test_Class/main_5.py", line 17, in <module>
                master.checkBox.clicked.connect(My_app.print_situation)
            AttributeError: 'function' object has no attribute '__pyqtSignature__'
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #31

              Why are you deriving from a QCheckBox and then create a new checkbox in it ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • C Offline
                C Offline
                California
                wrote on last edited by
                #32

                Would you be so kind to rewritte this code to loose error, because I am lost at the momment.
                A lot of time was spent for this issue in last month and I didn't make any progress at all.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  California
                  wrote on last edited by
                  #33

                  I will take no respond as this issue is mission impossible.
                  Thanks for your help.

                  Vlado

                  mrjjM 1 Reply Last reply
                  0
                  • C California

                    I will take no respond as this issue is mission impossible.
                    Thanks for your help.

                    Vlado

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #34

                    @California said in How to move class method out of gui modul:

                    mission impossible.

                    Well you seem to lack (some ?) understanding of classes in python.
                    https://www.tutorialspoint.com/python/python_classes_objects.htm

                    I think all the issue comes from that. Using Qt does not change anything.

                    So maybe stop with Qt for a day. Try to use own objects like you want to with Qt.

                    If you do not know how to make instance of a class or how to use them as parameters etc then
                    its hard to split to extra files.

                    Just saying. Im even bigger Beginner with python. :)

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      California
                      wrote on last edited by
                      #35

                      Thanks for this useffull link.

                      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