Answer the question
In order to leave comments, you need to log in
Pyqt4 | How to insert vbox into item (QTreeView and QTreeWidget)?
How to insert vbox into item (QTreeView and QTreeWidget)?
QTreeWidget
# -*- encoding: utf-8 -*-
from PyQt4 import QtGui, QtCore
import sys
app = QtGui.QApplication(sys.argv)
# === вставить этот vbox в item (например, в item_01)
vbox = QtGui.QVBoxLayout()
lbl = QtGui.QLabel('Текст')
vbox.addWidget(lbl)
# ===
treeWidget = QtGui.QTreeWidget()
treeWidget.setColumnCount(2)
treeWidget.setHeaderLabels(['Title', 'Summary']);
#First top level item_ and its kids
item_0 = QtGui.QTreeWidgetItem(treeWidget, ['Title 0', 'Summary 0'])
item_00 = QtGui.QTreeWidgetItem(item_0, ['Title 00', 'Summary 00'] )
item_01 = QtGui.QTreeWidgetItem(item_0, ['Title 01', 'Summary 01'])
#Second top level item_ and its kids
item_1 = QtGui.QTreeWidgetItem(treeWidget, ['Title 1', 'Summary 1'])
item_10 = QtGui.QTreeWidgetItem(item_1, ['Title 10', 'Summary 10'])
item_11 = QtGui.QTreeWidgetItem(item_1, ['Title 11', 'Summary 11'])
item_12 = QtGui.QTreeWidgetItem(item_1, ['Title 12', 'Summary 12'])
#Children of item_11
item_110 = QtGui.QTreeWidgetItem(item_11, ['Title 110', 'Summary 110'])
item_111 = QtGui.QTreeWidgetItem(item_11, ['Title 111', 'Summary 111'])
treeWidget.show()
sys.exit(app.exec_())
# -*- encoding: utf-8 -*-
from PyQt4 import QtGui, QtCore
import sys
app = QtGui.QApplication(sys.argv)
# === вставить этот vbox в item (например, в item_01)
vbox = QtGui.QVBoxLayout()
lbl = QtGui.QLabel('Текст')
vbox.addWidget(lbl)
# ===
model = QtGui.QStandardItemModel()
model.setHorizontalHeaderLabels(['Title', 'Summary'])
rootItem = model.invisibleRootItem()
#First top-level row and children
item_0 = [QtGui.QStandardItem('Title0'), QtGui.QStandardItem('Summary0')]
item_00 = [QtGui.QStandardItem('Title00'), QtGui.QStandardItem('Summary00')]
item_01 = [QtGui.QStandardItem('Title01'), QtGui.QStandardItem('Summary01')]
rootItem.appendRow(item_0)
item_0[0].appendRow(item_00)
item_0[0].appendRow(item_01)
#Second top-level item_ and its children
item_1 = [QtGui.QStandardItem('Title1'), QtGui.QStandardItem('Summary1')]
item_10 = [QtGui.QStandardItem('Title10'), QtGui.QStandardItem('Summary10')]
item_11 = [QtGui.QStandardItem('Title11'), QtGui.QStandardItem('Summary11')]
item_12 = [QtGui.QStandardItem('Title12'), QtGui.QStandardItem('Summary12')]
rootItem.appendRow(item_1)
item_1[0].appendRow(item_10)
item_1[0].appendRow(item_11)
item_1[0].appendRow(item_12)
#Children of item_11 (third level item_s)
item_110 = [QtGui.QStandardItem('Title110'), QtGui.QStandardItem('Summary110')]
item_111 = [QtGui.QStandardItem('Title111'), QtGui.QStandardItem('Summary111')]
item_11[0].appendRow(item_110)
item_11[0].appendRow(item_111)
treeView = QtGui.QTreeView()
treeView.setModel(model)
treeView.show()
sys.exit(app.exec_())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question