本文整理汇总了Python中PySide.QtGui.QListWidget.setAlternatingRowColors方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidget.setAlternatingRowColors方法的具体用法?Python QListWidget.setAlternatingRowColors怎么用?Python QListWidget.setAlternatingRowColors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QListWidget
的用法示例。
在下文中一共展示了QListWidget.setAlternatingRowColors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SubscriberDialog
# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import setAlternatingRowColors [as 别名]
class SubscriberDialog(QDialog):
if USE_MAEMO_5:
switchRequested = Signal()
def __init__(self, parent=None):
QDialog.__init__(self, parent)
self.ui = Ui_SubscriberDialog()
self.ui.setupUi(self)
self.subscriber = None
self.tableWidget = None
self.listWidget = None
if USE_MAEMO_5:
switchButton = self.ui.buttonBox.addButton(self.tr('Switch'), QDialogButtonBox.ActionRole)
switchButton.clicked.connect(self.switchRequested)
self.tableWidget = self.ui.tableWidget
headerLabels = ('Key', 'Value', 'Type')
self.tableWidget.setColumnCount(3)
self.tableWidget.setHorizontalHeaderLabels(headerLabels)
horizontalHeader = self.tableWidget.horizontalHeader()
horizontalHeader.setStretchLastSection(True)
verticalHeader = self.tableWidget.verticalHeader()
verticalHeader.setVisible(False)
self.tableWidget.setColumnWidth(0, 200)
self.tableWidget.setColumnWidth(1, 400)
else:
desktopWidget = QDesktopWidget()
if desktopWidget.availableGeometry().width() < 400:
# Screen is too small to fit a table widget without scrolling, use a list widget instead.
self.listWidget = QListWidget()
self.listWidget.setAlternatingRowColors(True)
self.ui.verticalLayout.insertWidget(2, self.listWidget)
else:
self.tableWidget = QTableWidget()
headerLabels = ('Key', 'Value', 'Type')
self.tableWidget.setColumnCount(3)
self.tableWidget.setHorizontalHeaderLabels(headerLabels)
horizontalHeader = self.tableWidget.horizontalHeader()
horizontalHeader.setStretchLastSection(True)
self.tableWidget.verticalHeader()
self.setVisible(False)
self.ui.verticalLayout.insertWidget(2, self.tableWidget)
self.ui.connectButton.clicked.connect(self.changeSubscriberPath)
self.changeSubscriberPath()
# if the default path does not exist reset it to /
value = self.subscriber.value()
subPaths = self.subscriber.subPaths()
if not value and not subPaths:
self.ui.basePath.setText('/')
self.changeSubscriberPath()
def changeEvent(self, e):
QDialog.changeEvent(self, e)
if e.type() == QEvent.LanguageChange:
self.ui.retranslateUi(self)
def changeSubscriberPath(self):
if self.listWidget:
self.listWidget.clear()
elif self.tableWidget:
self.tableWidget.clearContents()
if not self.subscriber:
self.subscriber = QValueSpaceSubscriber(self.ui.basePath.text(), self)
else:
self.subscriber.setPath(self.ui.basePath.text())
self.subscriber.contentsChanged.connect(self.subscriberChanged)
self.subscriber.connectNotify("contentsChanged()")
self.subscriberChanged()
def subscriberChanged(self):
subPaths = self.subscriber.subPaths()
if self.listWidget:
self.listWidget.clear()
elif self.tableWidget:
self.tableWidget.clearContents()
self.tableWidget.setRowCount(len(subPaths))
for i in xrange(len(subPaths)):
v = self.subscriber.value(subPaths[i])
if self.listWidget:
item = QListWidgetItem('%s (%s)\n%s' % (subPaths[i], str(type(v)), str(v)))
item.setFlags(item.flags() & ~Qt.ItemIsEditable)
self.listWidget.addItem(item)
elif self.tableWidget:
pathItem = QTableWidgetItem(subPaths[i])
pathItem.setFlags(pathItem.flags() & ~Qt.ItemIsEditable)
valueItem = QTableWidgetItem(str(v))
valueItem.setFlags(pathItem.flags() & ~Qt.ItemIsEditable)
typeItem = QTableWidgetItem(str(type(v)))
typeItem.setFlags(pathItem.flags() & ~Qt.ItemIsEditable)
self.tableWidget.setItem(i, 0, pathItem)
#.........这里部分代码省略.........