Skip to content

Instantly share code, notes, and snippets.

@StephenNneji
StephenNneji / icon_engine.py
Last active August 23, 2023 14:34
Simple theme icon switching using the QIconEgine
"Based on https://stackoverflow.com/a/76096769"
import sys
from PyQt6.QtWidgets import QApplication, QWidget, QToolButton, QComboBox, QVBoxLayout, QHBoxLayout
from PyQt6.QtGui import QIcon, QIconEngine, QPainter
from PyQt6.QtCore import QSize, QRect
themes = ['light', 'dark']
active_theme = themes[0]
light = '''
@StephenNneji
StephenNneji / main.py
Last active October 27, 2022 08:34
Singleton progress bar
"""
This is a demo of updating progress using a singleton class. This allow each class to
report its own progress without changing the argument list so that all functions recieve
a progrees object.
"""
from threading import Thread
import time
import sys
from PyQt5 import QtCore, QtWidgets
@StephenNneji
StephenNneji / validation.py
Last active June 2, 2022 17:15
Input validation in QT forms
import sys
from PyQt5.QtCore import pyqtSignal, QRegularExpression
from PyQt5.QtWidgets import (QApplication, QFrame, QLabel, QLineEdit,
QHBoxLayout, QVBoxLayout, QWidget, QPushButton)
class FormGroup(QWidget):
groupValidation = pyqtSignal(bool)
def __init__(self, orientation='vertical'):
super().__init__()
@StephenNneji
StephenNneji / oit.py
Last active June 9, 2018 17:37
Order Independent Transparency
import sys
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import (QApplication, QMainWindow, QOpenGLWidget,
QAction, QActionGroup, QFileDialog)
from OpenGL import GLU, GL
import numpy as np
class GLWidget(QOpenGLWidget):
def __init__(self, parent=None):
@StephenNneji
StephenNneji / custom_tabs.py
Last active September 2, 2021 20:39
Custom styled tabs in QT
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import (QApplication, QDialog, QWidget,
QLabel, QLineEdit, QHBoxLayout, QVBoxLayout, QPushButton,
QButtonGroup, QStackedLayout)
class Dialog(QDialog):
@StephenNneji
StephenNneji / demo_view.py
Last active November 1, 2023 01:55
Add checkbox in QTableView Header using icons
import numpy
from PyQt5 import QtCore, QtWidgets, QtGui
Qt = QtCore.Qt
class NumpyModel(QtCore.QAbstractTableModel):
def __init__(self, narray, parent=None):
QtCore.QAbstractTableModel.__init__(self, parent)
self._array = narray.point
self.test = narray.enabled