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. How to show all UI from another python file in current file when button is clicked.
QtWS25 Last Chance

How to show all UI from another python file in current file when button is clicked.

Scheduled Pinned Locked Moved Unsolved General and Desktop
47 Posts 4 Posters 13.8k 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.
  • M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 19 Aug 2019, 10:27 last edited by mrjj
    #34

    Well normally one would use App2 as that is the
    composite widget.
    So often that makes the most sense to use as it will then init the
    widget it uses in a proper way.

    S 1 Reply Last reply 19 Aug 2019, 10:29
    0
    • M mrjj
      19 Aug 2019, 10:27

      Well normally one would use App2 as that is the
      composite widget.
      So often that makes the most sense to use as it will then init the
      widget it uses in a proper way.

      S Offline
      S Offline
      sdf1444
      wrote on 19 Aug 2019, 10:29 last edited by
      #35

      @mrjj

      So I how do I show this in the main window. What is the overall code?

      M 1 Reply Last reply 19 Aug 2019, 10:47
      0
      • S sdf1444
        19 Aug 2019, 10:29

        @mrjj

        So I how do I show this in the main window. What is the overall code?

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 19 Aug 2019, 10:47 last edited by
        #36

        @sdf1444
        something like
        (import it )

        layout = QHBoxLayout()
        layout.addWidget(App2)
        yourwindow.setLayout(layout)
        yourwindow.show()

        S 1 Reply Last reply 19 Aug 2019, 11:25
        0
        • M mrjj
          19 Aug 2019, 10:47

          @sdf1444
          something like
          (import it )

          layout = QHBoxLayout()
          layout.addWidget(App2)
          yourwindow.setLayout(layout)
          yourwindow.show()

          S Offline
          S Offline
          sdf1444
          wrote on 19 Aug 2019, 11:25 last edited by
          #37

          @mrjj

          Hi

          I am getting this error when I add the layout code into pyqt.py: TypeError: addWidget(self, QWidget, stretch: int = 0, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = Qt.Alignment()): argument 1 has unexpected type 'sip.wrappertype'

          import sys
          from PyQt5.QtWidgets import *
          from PyQt5.QtCore import *
          from pyqt2 import *

          class App(QWidget):
          def init(self):
          QMainWindow.init(self)

              layout = QHBoxLayout()
              layout.addWidget(App2)
              yourwindow.setLayout(layout)
              yourwindow.show()
          
              pybutton = QPushButton('Click me', self)
              pybutton.resize(200,70)
              pybutton.move(400, 50)
              self.show()
          

          if name == "main":
          app = QApplication(sys.argv)
          mainWin = App()
          sys.exit(app.exec_())

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 19 Aug 2019, 12:11 last edited by
            #38

            Hi
            So
            app2 is NOT a QWidget ?
            i have no idea what "sip.wrappertype" is :)

            S 1 Reply Last reply 19 Aug 2019, 12:12
            0
            • M mrjj
              19 Aug 2019, 12:11

              Hi
              So
              app2 is NOT a QWidget ?
              i have no idea what "sip.wrappertype" is :)

              S Offline
              S Offline
              sdf1444
              wrote on 19 Aug 2019, 12:12 last edited by
              #39

              @mrjj

              "app2" is a widget created from inside class.

              M 1 Reply Last reply 19 Aug 2019, 12:14
              0
              • S sdf1444
                19 Aug 2019, 12:12

                @mrjj

                "app2" is a widget created from inside class.

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 19 Aug 2019, 12:14 last edited by
                #40

                @sdf1444
                it has to inherit QWidget or be a QWidget to be used in a layout.
                Else its plain impossible and you must create the inner Widgets yourself. :)

                S 1 Reply Last reply 19 Aug 2019, 12:24
                0
                • M mrjj
                  19 Aug 2019, 12:14

                  @sdf1444
                  it has to inherit QWidget or be a QWidget to be used in a layout.
                  Else its plain impossible and you must create the inner Widgets yourself. :)

                  S Offline
                  S Offline
                  sdf1444
                  wrote on 19 Aug 2019, 12:24 last edited by
                  #41

                  @mrjj

                  Hi "app2" is a QWidget.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sdf1444
                    wrote on 19 Aug 2019, 12:34 last edited by
                    #42

                    @mrjj

                    Because it is a QWidget it should be able to be shown but why do I get an error and is there another way to write this code because of an error.

                    M 1 Reply Last reply 19 Aug 2019, 12:40
                    0
                    • S sdf1444
                      19 Aug 2019, 12:34

                      @mrjj

                      Because it is a QWidget it should be able to be shown but why do I get an error and is there another way to write this code because of an error.

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 19 Aug 2019, 12:40 last edited by
                      #43

                      @sdf1444
                      make sure it's not because it miss a self in the right spot.

                      S 1 Reply Last reply 19 Aug 2019, 12:48
                      0
                      • M mrjj
                        19 Aug 2019, 12:40

                        @sdf1444
                        make sure it's not because it miss a self in the right spot.

                        S Offline
                        S Offline
                        sdf1444
                        wrote on 19 Aug 2019, 12:48 last edited by
                        #44

                        @mrjj

                        Where do I need a self?

                        M 1 Reply Last reply 19 Aug 2019, 14:01
                        0
                        • S sdf1444
                          19 Aug 2019, 12:48

                          @mrjj

                          Where do I need a self?

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 19 Aug 2019, 14:01 last edited by
                          #45

                          @sdf1444
                          It was just a suggestion.
                          I dont know if that is the case.

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 19 Aug 2019, 20:20 last edited by
                            #46

                            @sdf1444 said in How to show all UI from another python file in current file when button is clicked.:

                            class App(QWidget):
                            def init(self):
                            QMainWindow.init(self)

                            Why are you declaring App to be a QWidget and then in the constructor try to do some initialisation based on QMainWindow ?

                            Note that App is not a really good name for a widget. Most people would think of a QCore/QGui/QApplication based class.

                            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
                            • J Offline
                              J Offline
                              jhoney
                              Banned
                              wrote on 20 Aug 2019, 11:51 last edited by jhoney
                              #47
                              This post is deleted!
                              1 Reply Last reply
                              1

                              43/47

                              19 Aug 2019, 12:40

                              • Login

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