How to Create PyQt5 QTableWidget in Qt Designer

In this article we want to learn How to Create PyQt5 QTableWidget in Qt Designer , for creating of TableWidget we can use QTableWidget class from PyQt5, In PyQt5, QTableWidget is a class that provides table view for displaying and editing tabular data. it is powerful and powerful widget that can be used for displaying and editing data in different formats such as spreadsheets, databases and other structured data sources. QTableWidget provides table like view of data, with rows and columns that can be customized and arranged in different ways. it also  provides a number of features for editing and manipulating data, such as sorting, filtering, and searching.

 

 

These are some of key features of QTableWidget:

  1. Customizable appearance: QTableWidget provides different options for customizing the appearance of the table, including font, color, alignment and border styles.
  2. Editing support: QTableWidget supports editing of individual cells, allowing users to enter, edit and delete data directly within the table.
  3. Selection modes: QTableWidget supports different selection modes including single cell, row based and column based selection.
  4. Sorting and filtering: QTableWidget provides built in support for sorting and filtering of data and it allows users to quickly and easily find and manipulate data within the table.
  5. Context menus: QTableWidget supports context menus and it allows users to right click on cells to access different editing and formatting options.

 

So we can say that QTableWidget is powerful and powerful widget that provides different features for displaying and editing tabular data in PyQt5 applications. It is valuable tool for building complex and interactive user interfaces, and can be used in different types of applications and use cases.

 

 

 

 

You need to open your Qt Designer in PyQt5, because we want to create tablewidget using Qt Designer,  you can just write pyqt5designer in your terminal, after opening the Qt Designer you need to create Widgets window. now we add widgets in Qt Designer.

 

  • Add a QVBoxLayout in the Qt Designer 
  • Add a QTableWidget item in the QVBoxLayout 

 

 

So now you can add rows, columns and also items in your QTableWidget. right click on the tablewidget and click on the Edit Items, and from there you can add columns. so these are our columns.

QTableWidget in Qt Designer
QTableWidget in Qt Designer

 

 

 

These are rows for qtablewidget.

PyQt5 QTableWidget Rows
PyQt5 QTableWidget Rows

 

 

 

 

These are items for the qtablewidget.

PyQt5 QTableWidget Items
PyQt5 QTableWidget Items

 

 

 

 

Also you can add styles for the QTableWidget by right clicking on the tablewidget and choosing Change Stylesheet.

 

 

 

And this is our design.

Qt Designer QTableWidget
Qt Designer QTableWidget

 

 

 

 

After completing the design you need to save your design, the extension will be .ui file. now it is time to convert our .ui file in to .py file. there are two ways that you can do, first way is loading the ui file, the second way is converting the .ui file to .py file, we want to use the second way. for converting of the ui file to python file we need to use pyuic5 module, this module is located in the Scripts folder of your python installation, you need to copy your ui file in the Scripts folder of your Python installation. after that open the terminal in the Scripts folder, and run this command.

 

 

 

And this is the converted code.

 

 

 

 

So now run the complete code and this is result.

How to Create QTableWidget in Qt Designer
How to Create PyQt5 QTableWidget in Qt Designer

Leave a Comment

Share via
Copy link
Powered by Social Snap