Skip to content

Instantly share code, notes, and snippets.

import sys
from PyQt5 import QtGui, QtWidgets
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
view = QtWidgets.QGraphicsView()
scene = QtWidgets.QGraphicsScene()
import sys
from PyQt5 import QtWidgets, QtCore
class CustomTimer(QtCore.QThread):
countDownUpdated = QtCore.pyqtSignal(int) # whenever the countdown changes this signal get emitted
def __init__(self, count_down, sleep=1000, *args, **kwargs):
super(CustomTimer, self).__init__(*args, **kwargs)
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
class ClickableLabel(QtWidgets.QLabel):
# you will have to specify how many arguments and the type of the argument(eg: bool, int, str), in
# our case we will use QPoint to pass mouse position.
# All your signals must be class level, not object level/instance level.
clicked = QtCore.pyqtSignal(QtCore.QPoint)
import sys
from PyQt5 import QtWidgets, QtGui, QtCore
class CustomLabel(QtWidgets.QLabel):
def __init__(self, *args, **kwargs):
super(CustomLabel, self).__init__(*args, **kwargs)
self.start_point = QtCore.QPoint(0, 0) # This is x, y point, we will use Qpoint to represent it
self.end_point = QtCore.QPoint(0, 0) # The QPoint will only take two integers, QPointF for floating point
import sys
import os
from PyQt5 import QtWidgets, QtGui
class SampleWidget(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super(SampleWidget, self).__init__(*args, **kwargs)
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout
def change_button_text():
button.setText("Button has been clicked")
if __name__ == '__main__':
app = QApplication(sys.argv)
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout
_style = """
QWidget{
background-color: #f5fbff;
}
QLabel{
color: black;
import sys
from PyQt5.QtWidgets import QApplication, QLabel
from PyQt5.QtGui import QFont, QPalette, QColor
if __name__ == '__main__':
app = QApplication(sys.argv)
label = QLabel("hello")
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout
def change_button_text():
button.setText("Button has been clicked")
if __name__ == '__main__':
@PaulleDemon
PaulleDemon / PyQtSignalslotexample.py
Last active October 26, 2021 13:27
This is an example of signal and slot in pyqt
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout
def change_button_text():
button.setText("Button has been clicked")
if __name__ == '__main__':