i want to display two QTreeViews inside one window and i cant figure out why my testing code doesn't show the red widget (future 2nd TreeView). Any ideas why it doesn't appear?
I am new to PyQt5 and ive followed a tutorial on youtube and a written here. Before i started this question ive searched on stackoverflow, but i didn't find a topic which had this issue.
StandardItem
is a subclass of QStandardItem
and Color
is a subclass of QWidget
. Im not defining any layouts inside both classes (just setting default settings for QStandardItems and adding color to see my layout).
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowTitle("JSON View")
self.resize(700, 700)
treeView = QTreeView(self)
treeView.setHeaderHidden(True) # To hide first column
treeModel = QStandardItemModel()
rootNode = treeModel.invisibleRootItem()
# Data
america = StandardItem('America', 16, set_bold=True)
california = StandardItem('California', 14)
america.appendRow(california)
oakland = StandardItem('Oakland', 12)
california.appendRow(oakland)
rootNode.appendRow(america)
treeView.setModel(treeModel)
treeView.expandAll()
treeView.doubleClicked.connect(self.getValue)
# Layout
layout = QHBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(20)
layout.addWidget(Color('red'))
layout.addWidget(Color('yellow'))
layout.addWidget(treeView)
treeView.setVisible(True)
widget = QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)