title: PyQt5 connect Enter key to Widget
body: <p>Currently I am working with my own custom widget that consists of a <code>QLineEdit</code> and a <code>QPushButton</code>. A user is limited to entering an integer between 0 and 1000 in the text field. Upon clicking the button, the widget's custom <code>clicked</code> signal emits the value in the field.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>class ResizeWidget(QWidget):
  
      clicked = pyqtSignal(int)
  
      def __init__(self):
          super().__init__()
  
          #NumField and Button
          self.field = QLineEdit()
          self.field.setPlaceholderText("Resize Percentage [0,1000]")
          self.resizeButton = QPushButton("Resize")
  
          #Layout
          self.lay = QHBoxLayout()
          self.setLayout(self.lay)
  
          #Add to Widget
          self.lay.addWidget(self.field)
          self.lay.addWidget(self.resizeButton)
  
          #Field limits
          self.field.setMaxLength(4)
          self.field.setValidator(QIntValidator(0,1000))
  
          #Connection
          self.resizeButton.clicked.connect(self.onClick)
  
      @pyqtSlot()
      def onClick(self):
          val = int(self.field.text())
          self.clicked.emit(val)
  </code></pre>
  
  <p>Now what I'd like to add to the class is some way of allowing the user to press enter when the blinking cursor <code>|</code> sometimes called a 'caret' is in the text field.</p>
  
  <p>I am able to find documentation on the mouse in general, <code>mouseEvent</code> and <code>mousePressEvent</code> as a method within <code>QWidgets</code>. But I can't find any documentation that refers to the blinking cursor within the text field.</p>
  
  <p>I would like to add some sort of pseudocode like this within <strong>init</strong>():</p>
  
  <pre><code>if(cursor == inQLineEdit and pressedEnter):
      self.onClick()
  </code></pre>
  
  <p>I know <code>QLineEdit::returnPressed</code> plays a major role in creating the correct function but I only want the enter key to be valid if the user is using the ResizeWidget. Not some other part of my GUI. I would think the enter key isn't binded to only 1 widget in my entire application but I'd be interested to find out.</p>