Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
I may be slow to respond.

Edwin Yllanes eyllanesc

:octocat:
I may be slow to respond.
View GitHub Profile
@eyllanesc
eyllanesc / main.py
Created Aug 4, 2021
PDF Viewer with QtWebEngine
View main.py
import sys
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
def main():
print(
f"PyQt5 version: {QtCore.PYQT_VERSION_STR}, Qt version: {QtCore.QT_VERSION_STR}"
)
@eyllanesc
eyllanesc / main.py
Last active Apr 26, 2021
Load geojson that weigh more than 2MB in QtWebEngine
View main.py
import os.path
from PyQt5.QtWidgets import QApplication, QVBoxLayout, QWidget
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWebEngineCore import QWebEngineUrlRequestInterceptor
import folium
from qfolium import FoliumApplication
View builder.py
def _patch():
import os
import sys
import importlib.util
module_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "QtSiteConfig.py"
)
spec = importlib.util.spec_from_file_location("QtSiteConfig", module_path)
View main.py
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
from math import sqrt
class LogObject(QObject):
hovered = pyqtSignal()
notHovered = pyqtSignal()
View lang_es.ts
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="es">
<context>
<name>Form</name>
<message>
<location filename="main_ui.py" line="31"/>
<source>Form</source>
<translation>Formulario</translation>
</message>
View map.html
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script>L_PREFER_CANVAS=false; L_NO_TOUCH=false; L_DISABLE_3D=false;</script>
<script src="https://cdn.jsdelivr.net/npm/leaflet@1.3.4/dist/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1.3.4/dist/leaflet.css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"/>
View main.py
from PySide2 import QtCore, QtGui, QtWidgets
class InfoBox(QtWidgets.QGraphicsItem):
Type = QtWidgets.QGraphicsItem.UserType + 1
def __init__(self, parent=None):
super(InfoBox, self).__init__(parent)
self.setZValue(4)
proxy = QtWidgets.QGraphicsProxyWidget(self)
widget = QtWidgets.QLabel("TEST!")
View main.py
from PyQt5 import QtCore, QtWidgets
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self._gv = QtWidgets.QGraphicsView()
self.setCentralWidget(self._gv)
self._gv.viewport().installEventFilter(self)
def eventFilter(self, obj, event):
View main.py
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
def copy_widget(w):
if isinstance(w, QtWidgets.QWidget):
new_w = type(w)()
if isinstance(w, QtWidgets.QComboBox):
vals = [w.itemText(ix) for ix in range(w.count())]
new_w.addItems(vals)
return new_w
View main.py
import random
from PyQt5 import QtCore, QtGui, QtWidgets
class FlowLayout(QtWidgets.QLayout):
def __init__(self, parent=None, margin=-1, hspacing=-1, vspacing=-1):
super(FlowLayout, self).__init__(parent)
self._hspacing = hspacing
self._vspacing = vspacing
self._items = []
self.setContentsMargins(margin, margin, margin, margin)