0

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()
JokerMartini
  • 5,674
  • 9
  • 83
  • 193
  • One might argue that [doing your research](http://stackoverflow.com/help/how-to-ask) includes reading said docs... – Praveen Aug 26 '16 at 17:53
  • I get that and I've tried a few solutions thinking I understood it, but neither of them worked so i'm doing something wrong. just because there are doc's doesn't mean it'll always be understood – JokerMartini Aug 26 '16 at 18:01
  • Fair enough. You should probably include the results of your prior searches and attempts. It might help you get a better response. – Praveen Aug 26 '16 at 18:03
  • i can certainly do that :) i feel that i am close.. – JokerMartini Aug 26 '16 at 18:05
  • @Praveen do you know a solution to this? – JokerMartini Aug 26 '16 at 18:09
  • 1
    Unfortunately not. I'm not familiar with pyside. I just reviewed your question, so I tried giving you a friendly suggestion :-) – Praveen Aug 26 '16 at 18:11

0 Answers0