Hello,
I am currently using PyQt5 with Python3.
I'm having trouble getting a QTabWidget to be placed inside the main screen when called from a separate class.
Currently when the button "single" from the view menu option is selected a QTabWidget is produced but in a seperate window from my QMainWindow widget.
I believe the issue lies in my OOP but I was hoping for some input or direction to documentation that could provide me with a solution.
The structure is as follows:
__main__.py
mainscreen.App()
mainscreen.App()
To copy to clipboard, switch view to plain text mode
mainwindow.py
def __init__(self):
super().__init__() #is this line necessary
self.title = "PyQt EVE-Application"
self.showMaximized()
self.initUI()
sys.exit(appl.exec_())
def menu(self):
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('File')
openMenu = mainMenu.addMenu('Open')
viewMenu = mainMenu.addMenu('View')
helpMenu = mainMenu.addMenu('Help')
#FILE
exitButton.setShortcut('Ctrl + E')
exitButton.setStatusTip('Exit application')
exitButton.triggered.connect(self.close)
fileMenu.addAction(exitButton)
#OPEN
#VIEW
singleview
= QAction('Single View', self
) singleview.setShortcut ('Ctrl + S')
singleview.setStatusTip('Change view to one widget.')
singleview.triggered.connect(self.singlecall)
viewMenu.addAction(singleview)
# doubleview
doubleview
= QAction('Double View', self
) doubleview.setShortcut('Ctrl + D')
doubleview.setStatusTip('Change view to two wigets.')
doubleview.triggered.connect(widgetviews.double)
viewMenu.addAction(doubleview)
# tripleview
tripleview
= QAction('Triple View', self
) tripleview.setShortcut('Ctrl + T')
tripleview.setStatusTip('Change view to three widgets.')
tripleview.triggered.connect(widgetviews.triple)
viewMenu.addAction(tripleview)
# quadview
quadview
= QAction('Quad View', self
) quadview.setShortcut('Ctrl + Q')
quadview.setStatusTip('Change view to four widgets.')
quadview.triggered.connect(widgetviews.quad)
viewMenu.addAction(quadview)
#HELP
def singlecall(self):
self.t = widgetviews.single(self)
self.t.show()
def initUI(self):
self.setWindowTitle(self.title)
self.menu()
#default to quad view
self.show()
if __name__ == "__main__":
pass
class App(QMainWindow):
def __init__(self):
appl = QApplication(sys.argv)
super().__init__() #is this line necessary
self.title = "PyQt EVE-Application"
self.showMaximized()
self.initUI()
sys.exit(appl.exec_())
def menu(self):
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('File')
openMenu = mainMenu.addMenu('Open')
viewMenu = mainMenu.addMenu('View')
helpMenu = mainMenu.addMenu('Help')
#FILE
exitButton = QAction('Exit', self)
exitButton.setShortcut('Ctrl + E')
exitButton.setStatusTip('Exit application')
exitButton.triggered.connect(self.close)
fileMenu.addAction(exitButton)
#OPEN
#VIEW
singleview = QAction('Single View', self)
singleview.setShortcut ('Ctrl + S')
singleview.setStatusTip('Change view to one widget.')
singleview.triggered.connect(self.singlecall)
viewMenu.addAction(singleview)
# doubleview
doubleview = QAction('Double View', self)
doubleview.setShortcut('Ctrl + D')
doubleview.setStatusTip('Change view to two wigets.')
doubleview.triggered.connect(widgetviews.double)
viewMenu.addAction(doubleview)
# tripleview
tripleview = QAction('Triple View', self)
tripleview.setShortcut('Ctrl + T')
tripleview.setStatusTip('Change view to three widgets.')
tripleview.triggered.connect(widgetviews.triple)
viewMenu.addAction(tripleview)
# quadview
quadview = QAction('Quad View', self)
quadview.setShortcut('Ctrl + Q')
quadview.setStatusTip('Change view to four widgets.')
quadview.triggered.connect(widgetviews.quad)
viewMenu.addAction(quadview)
#HELP
def singlecall(self):
self.t = widgetviews.single(self)
self.t.show()
def initUI(self):
self.setWindowTitle(self.title)
self.menu()
#default to quad view
self.show()
if __name__ == "__main__":
pass
To copy to clipboard, switch view to plain text mode
tabwidget.py
def __init__(self, App):
super().__init__()
App.tab1.addTab(App.blankwidget, "Tab 1")
grid.addWidget(App.tab1,0,0)
grid.addWidget(App.tab2,0,1)
grid.addWidget(App.tab3,1,0)
grid.addWidget(App.tab4,1,1)
self.setLayout(grid)
class single(QWidget):
def __init__(self, App):
super().__init__()
App.blankwidget = QWidget()
App.tab1 = QTabWidget()
App.tab1.addTab(App.blankwidget, "Tab 1")
App.tab2 = QTabWidget()
App.tab3 = QTabWidget()
App.tab4 = QTabWidget()
grid = QGridLayout()
grid.addWidget(App.tab1,0,0)
grid.addWidget(App.tab2,0,1)
grid.addWidget(App.tab3,1,0)
grid.addWidget(App.tab4,1,1)
self.setLayout(grid)
To copy to clipboard, switch view to plain text mode
Thank you in Advance
Bookmarks