Creating Custom Widget for QListWidget in Qt 6

Some Basics

What is Qt?

Qt License Restriction

What are Signals and Slots?

Why Qt?

Project Structure

├── CMakeLists.txt
├── customwidget.cpp
├── customwidget.h
├── customwidget.ui
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
└── mainwindow.ui

Main Windows



Main window with empty QListWidget.
Main window with empty QListWidget.

Custom Widget



Widget with button, label and a horizontal spacer.
Widget with button, label, and a horizontal spacer.

Let’s Code

customwidget.cpp and customwidget.h

void setText(const QString &text)

void sendRemoveItem(const QString &text)

void on_toolButton_clicked()

mainwindow.cpp and mainwindow.h

Add Code to Constructor

void removeItem(const QString &text)

Connecting CustomWidget to MainWindow

Run the Application (GIF)

Application demo.
Application demo.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akshay Gollahalli

Akshay Gollahalli

PhD student, currently doing research on Spiking Neural Networks and Brain Computer Interfaces