PyQt6 Tutorials
About Lesson

In this PyQt6 lesson we are going to learn about How to Create QMenu in PyQt6,  pyqt6 QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.

 

 

This is the complete code for this lesson.

 

 

 

First of all we need to create a menubar, you can use the menuBar() method from QMainWindow, when you are going to create an application that has menubar and menu items than you need to extend from QMainWindow.

 

 

In here we have added a menu, for example we are going to just create a File menu.

 

 

Using this code you can create menu items, you can use QAction for these kind of functionalities and you can see that we have also added an icon for the menu item, make sure that you have already added icons in your working directory

 

 

If you want to create shortcut for your menu items than you can use setShortcut() method.

 

 

If you want to add separator between menu items than use this code.

 

 

There is a signal in menu items that is called triggered and we have connected that with the method that we want to create.

 

 

When we clicks on exit menu item than this method will be triggered.

 

 

 

Run the complete code and this is the result.

How to Create QMenu in PyQt6
How to Create QMenu in PyQt6