
- PyQt - Home
- PyQt - Introduction
- PyQt - Environment
- PyQt - Hello World
- PyQt - Major Classes
- PyQt - Using Qt Designer
- PyQt - Meta Objects
- PyQt Signals & Slots
- PyQt - Signals and Slots
- PyQt - Support and Signals
- PyQt - Unbound and Bound Signals
- PyQt - New Signals with PyQtSignal
- PyQt - Connecting, Disconnecting, & Emitting Signals
- PyQt - Slot decorator
- PyQt - Slot Connection
- PyQt Layouts
- PyQt - Layout Management
- PyQt - QBoxLayout
- PyQt - QGridLayout
- PyQt - QFormLayout
- PyQt - QHBoxLayout
- PyQt - QVBoxLayout
- PyQt - QStackedLayout
- PyQt - QGraphicsGridLayout
- PyQt - QGraphicsAnchorLayout
- PyQt - QGraphicsLayout
- PyQt - QGraphicsLinearLayout
- PyQt Basic Widgets
- PyQt - Basic Widgets
- PyQt - Qlabel Widget
- PyQt - QLineEdit Widget
- PyQt - QPushButton Widget
- PyQt - QRadioButton Widget
- PyQt - QCheckBox Widget
- PyQt - QComboBox Widget
- PyQt - QSpinBox Widget
- PyQt - QMessageBox
- PyQt - QDialogButtonBox Widget
- PyQt - QFontComboBox Widget
- PyQt - QDoubleSpinBox Widget
- PyQt - QToolBox Widget
- PyQt - QMenuBar, QMenu & Qaction Widgets
- PyQt - QToolTip
- PyQt - QInputDialog Widget
- PyQt - QFontDialog Widget
- PyQt - QDialog Widget
- PyQt - QFileDialog Widget
- PyQt - QTab Widget
- PyQt - QSplitter Widget
- PyQt - QDock Widget
- PyQt - QStatusBar Widget
- PyQt - QTabBar
- PyQt - QList Widget
- PyQt - QScrollBar Widget
- PyQt - QProgressBar
- PyQt - QCalendar Widget
- PyQt - QMessageBox Widget
- PyQt - QPlainTextEdit
- PyQt - QDateEdit
- PyQt - QDateTimeEdit
- PyQt - QTimeEdit
- PyQt - QTextEdit
- PyQt - QTextBrowser
- PyQt - QScrollArea
- PyQt - Drag and Drop
- PyQt - Multiple Document Interface
- PyQt - QDialog Class
- PyQt Views
- PyQt - QColumnView
- PyQt - QTableView
- PyQt Drawing API
- PyQt - Drawing API
- PyQt - Drawing a Line
- PyQt - Drawing a Rectangle
- PyQt - Drawing a Triangle
- PyQt - Drawing a Circle
- PyQt - Drawing a Ellipse
- PyQt - Drawing a Polygon
- PyQt - Geometric Transformation
- PyQt - Drawing Effect
- PyQt Groups
- PyQt - QButtonGroup
- PyQt - QGroupBox
- PyQt Effects
- PyQt - Effects
- PyQt - Opacity Effect
- PyQt - QGraphicsBlur Effect
- PyQt - QGraphicsColorize Effect
- PyQt - QGraphicsDropShadow Effect
- PyQt Events
- PyQt - Event Handling
- PyQt - Drag & Drop Events
- PyQt - File Open Event
- PyQt - Action Event
- PyQt - Hide Event
- PyQt - Resize Event
- PyQt Database
- PyQt - Database Handling
- PyQt Essentials
- PyQt - BrushStyle Constants
- PyQt - QClipboard
- PyQt - QPixmap Class
- PyQt Useful Resources
- PyQt - Quick Guide
- PyQt - Useful Resources
- PyQt - Discussion
PyQt - Column View
The QColumnView class in PyQt is used to display hierarchical data in a cascading list format. A seperate column is present in each hierarchy level which helos users to move from one level to another easily.This approach is often referred to as a cascading list, providing a structured and intuitive way to explore complex data sets.
The QcolumnView uses the Model/View(MV) architecture which seperates data presentation from logic. It leads to more maintainable and flexible UI's.
Understanding MV Architecture
In the MV architecture, the QAbstractItemModel class act as the model and it encapsulates the underlying data structure. The QAbstractItemView and QColumnView is responsible for displaying the model data and serve as view.
The seperation of Model and view helps in the following features −
- Data Reusability − The same model can be used for different display purpose.
- Increased Flexibility − If one model is modified the changes automatically occurs in all the views which reduces code duplication.
- Enhanced Maintainability − Changes to how data is displayed only require adjustments to the view, keeping the model independent.
Inheritance and structure
QColumnView is inherited from QAbstractitemView. It implements the interfaces defined by QAbstractItemView to interact with models derived from QAbstractItemModel.
Key Methods and Properties
Sr.No. | Methods & Description |
---|---|
1 |
columnWidths() Retrieves a list of current column widths. |
2 |
setColumnWidths(list) Sets the widths of all columns or the remaining columns if the list has fewer elements than the number of columns. |
3 |
initializeColumn(column) Copies the column view's properties (e.g., iconSize(), textElideMode(), alternatingRowColors()) to the specified column view. |
4 |
previewWidget() Gets the preview widget, used to display additional information for selected items (can be None). |
5 |
setPreviewWidget(widget) Sets the preview widget to display details about selected items. |
6 |
resizeGripsVisible() Determines whether resize grips are visible for column resizing (True by default). |
7 |
updatePreviewWidget(index)) Signals the need to update the preview widget based on the provided index. |
Example 1: Basic QColumnView Implementation
In the below example, we will create a simple PyQt application which shows a QcolumnView to display a hierarchical data model. We will use the default settings for column widths and appearance.
We initialize a QFileSystemModel to represent the file system hierarchy. The QColumnView is set to use this model, and the application is launched with app.exec_() method.
import sys from PyQt5.QtWidgets import QApplication, QColumnView, QFileSystemModel if __name__ == "__main__": app = QApplication(sys.argv) model = QFileSystemModel() model.setRootPath("") column_view = QColumnView() column_view.setModel(model) column_view.setWindowTitle("Basic QColumnView Example") column_view.show() sys.exit(app.exec_())
Output

Example 2: Customizing Column Widths
In this example we will use the setColumnWidths() method to set column widths for each column by passing a lsit of integer values to the fucntion parameter.
import sys from PyQt5.QtWidgets import QApplication, QColumnView, QFileSystemModel if __name__ == "__main__": app = QApplication(sys.argv) model = QFileSystemModel() model.setRootPath("") column_view = QColumnView() column_view.setModel(model) # Customize column widths widths = [200, 150, 250] # Set widths for each column column_view.setColumnWidths(widths) column_view.setWindowTitle("Customized Column Widths") column_view.show() sys.exit(app.exec_())
Output
On execution of above code, we get the following result −
