Skip to content

Instantly share code, notes, and snippets.

@oglops
Created February 15, 2016 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oglops/58baa552f0f428035978 to your computer and use it in GitHub Desktop.
Save oglops/58baa552f0f428035978 to your computer and use it in GitHub Desktop.
QListView + QStandardItemModel
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
data = ['row1', 'row2', 'row3']
class MyList(QListView):
def __init__(self, data, parent=None):
super(MyList, self).__init__(parent)
vertical_headers = []
# The follwing code could be put into main window class
# Create an empty model for the list's data
# using the listview as parent
model = QStandardItemModel(self)
for d in data:
item = QStandardItem(d)
item.setCheckable(True)
model.appendRow(item)
self.setModel(model)
def main(args):
app = QApplication(args)
my_list = MyList(data)
my_list.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment