Created
February 15, 2016 01:42
-
-
Save oglops/58baa552f0f428035978 to your computer and use it in GitHub Desktop.
QListView + QStandardItemModel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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