How to show the window title for selected widgets in Qstackwidget. Here is my code, In my code, if I select the Contact option, then I want to load "contact class" with window title.(look like tabwidget). If I select personal details, then person details window load with window title and so on (look like tabwidget,brower),
import sys
from PyQt5.QtWidgets import *
class stack1ui(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Contact Details")
self.layout = QFormLayout()
self.layout.addRow("Name", QLineEdit())
self.layout.addRow("Address", QLineEdit())
self.setLayout(self.layout)
class stack2ui(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Personal Details")
self.layout = QFormLayout()
self.sex = QHBoxLayout()
self.sex.addWidget(QRadioButton("Male"))
self.sex.addWidget(QRadioButton("Female"))
self.layout.addRow(QLabel("Sex"), self.sex)
self.layout.addRow("Date of Birth", QLineEdit())
self.setLayout(self.layout)
class stack3ui(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Educational Details")
self.layout = QHBoxLayout()
self.layout.addWidget(QLabel("subjects"))
self.layout.addWidget(QCheckBox("Physics"))
self.layout.addWidget(QCheckBox("Maths"))
self.setLayout(self.layout)
class stackedExample(QWidget):
def __init__(self):
super(stackedExample, self).__init__()
self.leftlist = QListWidget()
self.leftlist.insertItem(0, 'Contact')
self.leftlist.insertItem(1, 'Personal')
self.leftlist.insertItem(2, 'Educational')
self.stack1UI = stack1ui()
self.stack2UI = stack2ui()
self.stack3UI = stack3ui()
self.Stack = QStackedWidget(self)
self.Stack.addWidget(self.stack1UI)
self.Stack.addWidget(self.stack2UI)
self.Stack.addWidget(self.stack3UI)
hbox = QHBoxLayout(self)
hbox.addWidget(self.leftlist)
hbox.addWidget(self.Stack)
self.setLayout(hbox)
self.leftlist.currentRowChanged.connect(self.display)
self.setGeometry(300, 50, 10, 10)
self.setWindowTitle('StackedWidget demo')
self.show()
def display(self, i):
self.Stack.setCurrentIndex(i)
def main():
app = QApplication(sys.argv)
ex = stackedExample()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
