Skip to content

Instantly share code, notes, and snippets.

@frueter
Created September 20, 2022 20:22
Show Gist options
  • Save frueter/7d325cfc990703c866dd98807aabc73c to your computer and use it in GitHub Desktop.
Save frueter/7d325cfc990703c866dd98807aabc73c to your computer and use it in GitHub Desktop.
from PySide2 import QtWidgets, QtGui, QtCore
class ColumnView(QtWidgets.QColumnView):
def __init__(self, parent=None):
super().__init__(parent)
self.model = QtGui.QStandardItemModel()
self.setModel(self.model)
self.__get_data()
self.setColumnWidths([30, 30, 100])
preview_w = QtWidgets.QPushButton("What's with the extra column? >>>")
self.setPreviewWidget(preview_w)
def __get_data(self):
for i in ["a", "b", "c"]:
item = QtGui.QStandardItem(str(i))
self.model.appendRow(item)
for ii in ["d", "e", "f"]:
item2 = QtGui.QStandardItem(str(ii))
item.appendRow(item2)
for iii in ["g", "h", "i"]:
item3 = QtGui.QStandardItem(str(iii))
item2.appendRow(item3)
if __name__ == '__main__':
import sys
args = sys.argv
app = QtWidgets.QApplication(args)
w = ColumnView()
w.show()
w.resize(800, 500)
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment