Pyside2 GUI How To Create Tooltip

In this Pyside2 GUI Development i want to show you How To Create Tooltip , so before this we had some articles on Pyside2 GUI Development, you can check them in the below links.

 

 

Check Python GUI Development With Pyside2

 

1: Getting Started With Pyside2 | Qt For Python 

2: Pyside2 GUI Creating First Window 

3: Pyside2 GUI Creating Window Icon

4: Pyside2 GUI How To Create Icon Modes

 

 

What is QTooltip ?

The tip is a short piece of text reminding the user of the widget’s function. It is drawn immediately below the given position in a distinctive black-on-yellow color combination. The tip can be any rich text formatted string.

 

So now this is the complete code for Pyside2 GUI How To Create Tooltip

 

 

 

OK in the above code  first we have imported our classes from Pyside2 library

 

 

 

And this is our main window class that inherits from QWidget, in that class we are going to add the window title , window geometry and minimum width and height for the window.

also you can check Python Object Oriented Programming Articles in the link. Python Object Oreinted Programming. also we have set the tooltip for the window

 

 

 

This is the method that we are going to set our icon, make sure that you have an icon in your working directory, as i have already added an icon to

my working directory. so in here first you need to create the QIcon object and after that you set the window icon by using setWindowIcon().

 

 

And in here we are going to set our three different type icon modes, also we add tooltip for every of our icon using setTooltip() ,  basically A QIcon can generate smaller, larger, active, and disabled pixmaps from the set of pixmaps it is given. Such pixmaps are used by Qt widgets to show an icon representing a particular action. make sure that you have an icon in your working directory.

 

 

 

So in here every Pyside2 application must create an application object. The sys.argv parameter is a list of arguments from a command line.

Python scripts can be run from the shell. It is a way how we can control the startup of our scripts.

 

 

 

Finally, we enter the mainloop of the application. The event handling starts from this point. The mainloop receives events from the window system and dispatches them to the application widgets. The mainloop ends if we call the exit() method or the main widget is destroyed. The sys.exit() method ensures a clean exit. The environment will be informed how the application ended.

The exec_() method has an underscore. It is because the exec is a Python keyword. And thus, exec_() was used instead.

 

 

 

 

So now run the complete code and this will be the result

 

Pyside2 GUI How To Create Tooltip
Pyside2 GUI How To Create Tooltip

 

 

 

Also you can watch the complete video for this article

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×