PyQt5 QtQuick QML Creating Grid

In this PyQt5 QtQuick QML article iam going to show you Creating Grid, also iam going to show you creating of repeaters in QML. so first of all let’s talk about Grid in PyQt5.

 

 

PyQt5 QtQuick QML Tutorial: Creating Grid and Repeater

Grid is a type that positions its child items in grid formation. A Grid creates a grid of cells that is large enough to hold all of its child items, and places these items in the cells from left to right and top to bottom. Each item is positioned at the top-left corner of its cell with position (0, 0). A Grid defaults to four columns, and creates as many rows as are necessary to fit all of its child items. The number of rows and columns can be constrained by setting the rows and columns properties.

 

 

 

Creating Grid in PyQt5 QtQuick QML

OK now you need to create two files in your Pycharm IDE, the first one is grid.qml and the second one main.qml, This is our grid.qml.

 

 

 

This is our main window and there are the width and height for the window.

 

 

OK now this is the grid, you can see that we have columns and rows for our grids.

 

Also we are going to create  repeater and we give the size of 16 for the repeater. because we want to create 16 rectangle.

Understanding Repeater in PyQt5 QtQuick QML

So the Repeater type is used to create a large number of similar items. Like other view types, a Repeater has a model and a delegate: for each entry in the model, the delegate is instantiated in a context seeded with data from the model. A Repeater item is usually enclosed in a positioner type such as Row or Column to visually position the multiple delegate items created by the Repeater.

 

 

 

Running the PyQt5 QtQuick QML Application

To run the complete application, we use PyQt5 to load and execute the QML file. This is a Python code to run the QML application:

 

 

 

 

 

Run the complete code and this will be the result

PyQt5 QtQuick QML Creating Grid
PyQt5 QtQuick QML Creating Grid

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×