How to show all UI from another python file in current file when button is clicked.
-
@sdf1444
something like
(import it )layout = QHBoxLayout()
layout.addWidget(App2)
yourwindow.setLayout(layout)
yourwindow.show()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_()) -
Hi
So
app2 is NOT a QWidget ?
i have no idea what "sip.wrappertype" is :) -
@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. :) -
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.
-
@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.