PyQt5 draggable Custom window code

When you are working with PyQt5, you are using the default OS style of application. The design looks very simple for apps. So, if you are making a cutom app, you will cuystomise the top bar in few cases to have a better design. So, when you are customising the design, you will see that the window has no longer been movable. Thus, you need to write the logic to make the window movable again.
The default Window app style looks like this

The code for doing this is given below...

PyQt5 draggable window Code


class movable(QtWidgets.QWidget):
    def __init__(self):
        super(movable, self).__init__()
    def mousePressEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton:
            self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()
            event.accept()
    def mouseMoveEvent(self, event):
        if event.buttons() == QtCore.Qt.LeftButton:
            self.move(event.globalPos() - self.dragPosition)
            event.accept()

You will have to first make a class like this. Then you have to pass the class as parameter in the main window code. Like this...


class mainWindow(movable, Ui_Form):
    def __init__(self):


Here UI form is the form of the design.

So, I think that's it for this post. See you in the next...

Make your own Python IDE + Text Editor like Notepad:

July 17, 2021, 4:33:43 PM (MrDev in a deep thought)

If you have used Python, you must be aware of the Python shell (the IDLE). We have one place where we write the code and to run the code, we need to switch between the windows. Some brilliant mind will say (with a sarcastic sound) "He calls himself a programmer and he is talking about IDLE... Lol hahaha."

Shut up! Okay? I use IDEs but something that you have made, even its worse than what you think that was worse, you will like that! And a programmer builds things. This is his work.

Now in this project, I created my own IDE with python using Tkinter.

Now let me assume that some of you are from Mars and they don't know what IDEs actually are? So basically, IDE stands for Integrated Development Environment. It provides a collection of different things needed for coding and creates an environment for coding fast. Well its obvious that I could not make something at once that can directly challenge VS code (one of the leading IDEs in). But I can make something more similar to a text editor (like Notepad). And basically, what we actually want in programming is a section to run the program and display the output. So, can't we combine the output and the editor part in the same window. So, it reduces our work to switch between the windows like we do in IDLE.

Well, that's all about the idea. I am going to create a new notepad. But don't laugh. Okay. It would have some more features than notepad. Believe me! Let's start!

>>> Test 1: ✔
>>> Test 2: ✔
>>> Test 3: ✔
>>> Test 4: ✔
...

Code Link

0 Comments