In this article we will see how we can drag the text/content i.e whole text including prefix and suffix from it. When we create a spin box we can't drag text from it, dragging text means moving the selected text any where according to the cursor.
In order to do this we use setDragEnabled method with the line edit object of spin box.
Syntax : line_edit.setDragEnabled(True)
Argument : It takes bool as argument
Return: It returns None
Below is the implementation
Python3 1==
# importing librariesfromPyQt5.QtWidgetsimport*fromPyQt5importQtCore,QtGuifromPyQt5.QtGuiimport*fromPyQt5.QtCoreimport*importsysclassWindow(QMainWindow):def__init__(self):super().__init__()# setting titleself.setWindowTitle("Python ")# setting geometryself.setGeometry(100,100,600,400)# calling methodself.UiComponents()# showing all the widgetsself.show()# method for widgetsdefUiComponents(self):# creating spin boxself.spin=QSpinBox(self)# setting geometry to spin boxself.spin.setGeometry(100,100,250,40)# setting prefix to spinself.spin.setPrefix("Prefix ")# setting suffix to spinself.spin.setSuffix(" Suffix")# getting the line edit objectline=self.spin.lineEdit()# enabling the drag line.setDragEnabled(True)# create pyqt5 appApp=QApplication(sys.argv)# create the instance of our Windowwindow=Window()# start the appsys.exit(App.exec())