PyQt4 Model View Tutorial Part 01_1

Yasin Uludag · 81K views · 2011 · 10:01

Open on YouTube

Python, Ruby & scripting languagesSoftware architecture & designtutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when pointing PyQt beginners to a worked introduction to Qt's model/view (MVC) approach.

Recommended by 2 people across 2 different months, 2009 to 2020.

What it is

A 10-minute screencast by Yasin Uludag, the first part of a PyQt4 series introducing Qt's model/view architecture in Python. It walks through a basic model and view example, with the source code linked in the description.

What people said

Recommends cmaynard · 2009-11 · Stack Overflow · on “PyQt and MVC-pattern”

One of the first things you should do is use Qt4 designer to design your gui and use pyuic4 to generate your python GUI. This will be your view, you NEVER edit these python files by hand. Always make changes using designer, this ensures your View is separate from your model and control. For the control element, create a central class that inherits from your base gui widget such as QMainWindow. This object will then contain a member ui that is your view object you just generated. here is an example from a tutorial [LINK] UPDATE 2013: Here is a more recent tutorial(s) on PyQt and MVC Model PyQt MVC Tutorial Series [this video] import sys from PyQt4 import QtCore, QtGui from edytor import Ui_notepad

Recommends lps · 2016-04 · Stack Overflow · on “PyQt QTreeWidgetItem Individual windows with individual data.”

Why don't you start with studying how the standard MVC is implemented in Qt? The following resources should be a good start for you: this intro site [LINK] or this video series [this video]

Cites Alan · 2020-05 · Stack Overflow · on “How to Use QListView to Select Which Columns are Displayed in QTableView”

Suppose I have the following dataframe: df = {'Banana': {0: 1, 1: 2, 2: 5}, 'Apple': {0: 3, 1: 4, 2: 3}, 'Elderberry': {0: 5, 1: 4, 2: 1}, 'Clementine': {0: 4, 1: 7, 2: 0}, 'Fig': {0: 1, 1: 9, 2: 3}} Banana Apple Elderberry Clementine Fig 0 1 3 5 4 1 1 2 4 4 7 9 2 5 3 1 0 3 Which is passed to QAbstractTableModel and displayed with QTableView : import sys from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.Qt import Qt import pandas as pd class MainWindow(QtWidgets.QMainWindow): def __init__(self, model): super().__init__() self.model = model self.table = QtWidgets.QTableView() self.table.setModel(self.model) self.setCentralWidget(self.table) class TableModel(QtCore.QAbstractTableModel): de