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. [Python] A class object inside the class
Forum Updated to NodeBB v4.3 + New Features

[Python] A class object inside the class

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.0k 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.
  • S Offline
    S Offline
    SiriusWhite
    wrote on last edited by
    #1

    Hello, how could i create, for example, Qt button in Qt widget class. I imagine that would like something like this:
    @class Window(QtGui.QWidget):
    def init(self):
    #...
    self.button = ButtonClass()
    button.show()

    class ButtonClass(...)
    def init(self):
    #...
    def show(self):
    self.show()@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      are you looking for something like "this":http://qt-project.org/wiki/PySideTutorials_Clickable_button ?

      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
      • S Offline
        S Offline
        SiriusWhite
        wrote on last edited by
        #3

        Hey, thanks.
        That's right but i want to create neutral button and window classes so i could create many similiar buttons in a window (widget) class with different variables for each. In C# it is pretty simple (it's enough to do public class and then create object of it) but i have no idea how to do that in Python.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What do you mean by neutral button ?

          Could you show an simple example of what you would like to achieve (even in pseudo code)

          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
          • S Offline
            S Offline
            SiriusWhite
            wrote on last edited by
            #5

            By saying neutral button i mean a class which can be used for creating more than two buttons just by defining other parameters and basicly is not for repeating the similiar code twice.

            This is an example how it must look (im not good at python, etc. in C# it is possible to do with pointers):
            @#Global object popUpWindow?

            class ButtonClass(...)
            def init(self): #and parameters after 'self' for title and text
            #...
            self.title = "Press this button" #first parameter
            self.text = "My text" #pop-up text, used in new window
            # These must be defined by creating object or defined later. Etc. firstButton = ButtonClass("Press this button","My text")
            button = QPushButton(self.title) # Creating exact button but it must be in Window object
            button.clicked.connect(setTextInWindow())

            def setTextInWindow(self):
            # Use global object here? and show popUpWindow with self.text label

            def show(self):
            self.show()

            class Window(QtGui.QWidget):
            def init(self):
            #...
            self.button = ButtonClass("""Parameters here""")
            button.show() # then show the button in main window

            class popUpWindow(QtGui.QWidget):

            ... Blank window only with text label from ButtonClass

            #Program main first calls Window then ButtonClass must be called by placing a button in Window widget. By pressing the button the pop-up appears (popUpWindow)@

            This must be pretty clear. A thing is that i don't know how to manage classes.
            EDIT: I have managed to find out a solution. Thank you for you help.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Greate you found out !

              Don't use show on each button/sub-widget, put everything in a layout, that will manage position etc… for you.

              Since you have it working, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

              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

              • Login

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