Skip to content

Instantly share code, notes, and snippets.

@FloydanTheBeast
Created January 12, 2020 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FloydanTheBeast/d8e110f4cf58054c23000dd93b28c501 to your computer and use it in GitHub Desktop.
Save FloydanTheBeast/d8e110f4cf58054c23000dd93b28c501 to your computer and use it in GitHub Desktop.
Event handler override example
from PyQt5.QtWidgets import QApplication, QWidget, QMessageBox, QLabel, QVBoxLayout
from PyQt5.QtCore import Qt
class UI(QWidget):
def __init__(self):
super().__init__()
layout = QVBoxLayout()
self.label = QLabel('x: _; y: _')
self.label.setStyleSheet('font-size: 48px; font-weight: 800')
layout.addWidget(self.label)
layout.setAlignment(Qt.AlignCenter)
self.setLayout(layout)
self.showFullScreen()
def mousePressEvent(self, e):
self.label.setText(f'x: {e.x()}; y: {e.y()}')
if __name__ == '__main__':
app = QApplication([])
ui = UI()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment