Home > Blockchain >  How do I use the double click signal in the QLineEdit widget?
How do I use the double click signal in the QLineEdit widget?

Time:11-18

I have a QLineEdit widget and I want to use the double click event on it. How can I do that?

def __init__(self):
    #... other codes

    self.title = QLineEdit()
    self.title.returnPressed.connect(self.lockTitle)

    #like this -> 'self.title.doubleClicked.connect(self.unlockTitle)'

    #... other codes 
def lockTitle(self):
    self.title.setDisabled(True)

def unlockTitle(self):
    self.title.setDisabled(False)

CodePudding user response:

A possible solution is to create a custom QLineEdit by creating a new signal that is emitted in the mouseDoubleClickEvent method, but the problem in your case is that the QLineEdit is disabled and that method is not invoked so instead of using that method you should use the event method:

class LineEdit(QLineEdit):
    doubleClicked = pyqtSignal()

    def event(self, event):
        if event.type() == QEvent.Type.MouseButtonDblClick:
            self.doubleClicked.emit()
        return super().event(event)
self.title = LineEdit()
self.title.returnPressed.connect(self.lockTitle)
self.title.doubleClicked.connect(self.unlockTitle)
  • Related