本文整理匯總了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)
#.........這裏部分代碼省略.........