How to show all UI from another python file in current file when button is clicked.
-
@sdf1444
well something like
layout = QHBoxLayout()
layout.addWidget(button1) // button1 would be your imported widget instancewindow.setLayout(layout)
window.show()window most like being mainwindow
its a good idea to read about layouts
https://doc.qt.io/qtforpython/overviews/layout.html
so you know what you are using :) -
@sdf1444
well something like
layout = QHBoxLayout()
layout.addWidget(button1) // button1 would be your imported widget instancewindow.setLayout(layout)
window.show()window most like being mainwindow
its a good idea to read about layouts
https://doc.qt.io/qtforpython/overviews/layout.html
so you know what you are using :) -
Hi
but a widget is a class. ?
so you import, you create an instance and insert into layout.It should not be an issue to integrate it with the code you have.
Maybe you already have a layout. else now would be a good time to use one :) -
Hi
but a widget is a class. ?
so you import, you create an instance and insert into layout.It should not be an issue to integrate it with the code you have.
Maybe you already have a layout. else now would be a good time to use one :) -
Hi
but a widget is a class. ?
so you import, you create an instance and insert into layout.It should not be an issue to integrate it with the code you have.
Maybe you already have a layout. else now would be a good time to use one :) -
So how would I create instances of the classes which have multiple widgets and then insert into the layout?
Thanks
@sdf1444
Hi
what you say, classes, you mean normal python classes that use widgets or what do you mean?
I can't answer that as it would be either you create the master class (composite) then (if its a widget) or
you would create each widget by itself if the "class" if not a widget and you don't want to show it.
However, it really depends on what you import. -
@sdf1444
Hi
what you say, classes, you mean normal python classes that use widgets or what do you mean?
I can't answer that as it would be either you create the master class (composite) then (if its a widget) or
you would create each widget by itself if the "class" if not a widget and you don't want to show it.
However, it really depends on what you import.Basically this is an widget created inside a class. So I am importing widgets which are inside a master class. How do I instantiate this, and then insert into a layout?
class App2(QWidget): def init(self): QMainWindow.init(self) pybutton = QPushButton('hi', self) pybutton.resize(200,70) pybutton.move(900, 50) self.show()
-
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. -
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. -
@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.