我将Qwidget
( QPushButton
) 添加到QTreeWidget
throughsetItemWidget
方法中,但 Button 未按预期显示。
在这种情况下需要一些帮助。
代码:
import sys
from PyQt4 import QtGui, QtCore
class Test_Ui(QtGui.QMainWindow):
def __init__(self):
super(Test_Ui, self).__init__()
self.setMainWidget()
self.setTree()
self.show()
def setMainWidget(self):
self.QwCentral = QtGui.QWidget()
self.setCentralWidget(self.QwCentral)
self.QglCentral = QtGui.QGridLayout()
self.QwCentral.setLayout(self.QglCentral)
def setTree(self):
self.QtwExp = QtGui.QTreeWidget()
self.QtwExp.headerItem().setText(0, 'First')
self.QtwExp.headerItem().setText(1, 'Second')
self.QglCentral.addWidget(self.QtwExp, 0,0)
Qcategory = QtGui.QTreeWidgetItem()
Qcategory.setText(0, 'TEST')
self.QtwExp.addTopLevelItem(Qcategory)
Qbutton = QtGui.QPushButton()
Qbutton.setText('BUTTON')
# setItem Widget Command
self.QtwExp.setItemWidget(Qcategory, 1, Qbutton)
def main():
global wapp
app = QtGui.QApplication(sys.argv)
wapp = Test_Ui()
sys.exit(app.exec_())