Can someone show me how to sort my list of items ignoring case sensitivity? I've searched around online on numerous forums and most of them are in the wrong syntax, over-complicated or just point to some docs. I've still now found a working solution so any help would be great.
import sys
from PySide import QtGui, QtCore
class Example(QtGui.QMainWindow):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.uiItems = QtGui.QListView()
self.uiItems.setAlternatingRowColors(True)
self.uiItems.setModel(self.createModel(self))
self.uiItems.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
grid = QtGui.QGridLayout()
grid.setContentsMargins(0, 0, 0, 0)
grid.addWidget(self.uiItems, 0, 0)
self.setLayout(grid)
self.setLayout(grid)
# main layout
main_widget = QtGui.QWidget()
main_widget.setLayout(grid)
self.setCentralWidget(main_widget)
self.uiItems.doubleClicked.connect(self.doubleClickedItem)
self.show()
def doubleClickedItem(self, item):
name = item.data(role=QtCore.Qt.DisplayRole)
self.results = name
self.accept()
def createModel(self, parent):
items = [
'Cookie dough',
'Hummus',
'Spaghetti',
'Dal makhani',
'Chocolate whipped cream',
'candles',
'Apples',
'zebra',
'Oranges'
]
model = QtGui.QStandardItemModel()
for item in items:
model.appendRow(QtGui.QStandardItem(item))
return model
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()