首页 > 代码库 > pyqt显示下拉内容
pyqt显示下拉内容
# -*- coding: cp936 -*-
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class InlineEditor(QWidget):
_MUTE = ‘MUTE‘
def __init__(self, parent):
QWidget.__init__(self, parent)
self.setAutoFillBackground(True)
lo = QHBoxLayout()
lo.setMargin(0)
lo.setSpacing(4)
self._cbFoo = QComboBox()
for x in ["ABC", "DEF", "GHI", "JKL"]:
self._cbFoo.addItem(x)
self._leBar = QLineEdit(‘‘, self)
self._leBar.setValidator(QIntValidator(0, 999999, self))
lo.addWidget(self._cbFoo, 3)
lo.addSpacing(5)
lo.addWidget(QLabel(‘Bar:‘))
lo.addWidget(self._leBar, 3)
lo.addStretch(5)
self.setLayout(lo)
class Form(QDialog):
def __init__(self,parent=None):
QDialog.__init__(self, parent)
grid = QGridLayout()
tree = QTreeWidget()
tree.setColumnCount(2)
for n in range(3):
i = QTreeWidgetItem(tree) # 创建QTreeWidget的子项目i
i.setText(0,"first " + str(n)) # 设置第0列的文本
i.setText(1,"second")
for m in range(3):
j = QTreeWidgetItem(i) # 为QTreeWidget子项目i创建子项目
j.setText(0,"child first "+str(m))
b1 = QCheckBox("push me 0",tree) # 注意此处第二个参数,如果没有这个参数创建不成功
tree.setItemWidget(tree.topLevelItem(0).child(1), 1, b1) #在第一个项目的第一个子项目的第2列中放置控件。
item=InlineEditor(tree) # 处理多个控件的组合
tree.setItemWidget(tree.topLevelItem(0).child(1), 1, item)
grid.addWidget(tree)
self.setLayout(grid)
app = QApplication([])
form=Form()
form.show()
app.exec_()
如图:
pyqt显示下拉内容