Skip to content

Instantly share code, notes, and snippets.

View MaurizioB's full-sized avatar

MaurizioB

View GitHub Profile
@MaurizioB
MaurizioB / highlightHover.py
Created September 29, 2021 16:55
QTextEdit with highlight on hover
from PyQt5 import QtCore, QtGui, QtWidgets
from random import randrange, choice
from string import ascii_lowercase as letters
class HighlightTextEdit(QtWidgets.QTextEdit):
_highlightColor = QtGui.QColor('#FFFF00')
_highlightUnderline = False
highlightPos = -1, -1
def __init__(self, *args, **kwargs):
@MaurizioB
MaurizioB / romanencoder.py
Last active June 26, 2022 02:47
Roman numeral encoding, based on XKCD#2637
import re
from PyQt5.QtWidgets import (QApplication, QVBoxLayout, QWidget, QLabel, QTextEdit)
'''
Inspired by https://xkcd.com/2637/
Based on the Python code of tools/roman.py
'''
RomanNumbers = 'ivxlcdmIVXLCDM'
@MaurizioB
MaurizioB / pyqt-closure.py
Last active May 19, 2024 23:29
Example of closure issues when using instances without persistent references
from PyQt5.QtWidgets import *
class Dummy:
def __init__(self):
self.box = QGroupBox()
self.label1 = QLabel()
self.label2 = QLabel()
layout = QVBoxLayout(self.box)