X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=testother.py;fp=testother.py;h=7c0f7668f6adc11b68a33c34928281b3e2367ec9;hb=d001770946053c4d60f9f9b9362f713287013079;hp=0000000000000000000000000000000000000000;hpb=3a76135cf3477fc8e8e0508ff8fd1026c21c6281;p=retroconv diff --git a/testother.py b/testother.py new file mode 100644 index 0000000..7c0f766 --- /dev/null +++ b/testother.py @@ -0,0 +1,48 @@ +import sys +from PyQt4.QtCore import * +from PyQt4.QtGui import * + +#################################################################### +def main(): + app = QApplication(sys.argv) + w = MyWindow() + w.show() + sys.exit(app.exec_()) + +#################################################################### +class MyWindow(QWidget): + def __init__(self, *args): + QWidget.__init__(self, *args) + + # create table + list_data = ["Tarek","Ehab","Galal"] + lm = MyListModel(list_data, self) + lv = QListView() + lv.setViewMode(QListView.IconMode) + lv.setModel(lm) + + # layout + layout = QVBoxLayout() + layout.addWidget(lv) + self.setLayout(layout) + +#################################################################### +class MyListModel(QAbstractListModel): + def __init__(self, datain, parent=None, *args): + """ datain: a list where each item is a row + """ + QAbstractListModel.__init__(self, parent, *args) + self.listdata = datain + + def rowCount(self, parent=QModelIndex()): + return len(self.listdata) + + def data(self, index, role): + if index.isValid() and role == Qt.DisplayRole: + return QVariant(self.listdata[index.row()]) + else: + return QVariant() + +#################################################################### +if __name__ == "__main__": + main()