Skip to content

Instantly share code, notes, and snippets.

View jniemann66's full-sized avatar

Judd Niemann jniemann66

  • Melbourne
View GitHub Profile
@jniemann66
jniemann66 / deployApp.cmd
Created May 3, 2018 01:39
Qt Deploy Qt Virtual Keyboard (requires Enterprise Qt) to build dir
rem deploy Qt Virtual Keyboard to project Build Directory
set qtdir=C:\Qt\5.9.5\msvc2015_64
set builddir=C:\Development\qt\build\x86_64
%qtdir%\bin\windeployqt.exe %builddir%\App.exe
copy /Y %qtdir%\bin\Qt5Qml.dll %builddir%
copy /Y %qtdir%\bin\Qt5Quick.dll %builddir%
copy /Y %qtdir%\plugins\platforminputcontexts\qtvirtualkeyboardplugin.dll %builddir%
@jniemann66
jniemann66 / richtextdelegate.cpp
Created June 11, 2018 23:01
Qt Rich Text Delegate
#include "richtextdelegate.h"
#include <QPainter>
#include <QTextDocument>
RichTextDelegate::RichTextDelegate(QObject *parent) : QStyledItemDelegate(parent)
{
}
void RichTextDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
@jniemann66
jniemann66 / checkboxdelegate.cpp
Last active June 30, 2018 02:43
Qt: CheckBoxDelegate class
#include "checkboxdelegate.h"
#include <QApplication>
CheckBoxDelegate::CheckBoxDelegate(QObject *parent) : QStyledItemDelegate(parent), scale(1.1) {}
void CheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QRect rect(option.rect.left() / scale, option.rect.top() / scale, option.rect.width() / scale, option.rect.height() / scale);
painter->save();
@jniemann66
jniemann66 / swipetoeditdelegate.cpp
Created July 13, 2018 06:08
Qt Swipe-To-Edit Delegate
#include "swipetoeditdelegate.h"
#include <QApplication>
#include <QDebug>
#include <QMouseEvent>
#include <QTextDocument>
SwipeToEditDelegate::SwipeToEditDelegate(QObject* parent) : QStyledItemDelegate(parent), minRectWidth(10), activationThreshold(0.5), color("red")
{
}
@jniemann66
jniemann66 / printJSON.cpp
Last active March 8, 2019 04:58
Qt printJSON - format a QJsonValue into a string, and just report length of large strings or arrays
#include "printjson.h"
#include <QJsonObject>
#include <QJsonValue>
#include <QJsonArray>
#include <QVariant>
#include <QTextStream>
#include <QRegularExpression>
QString sprintJson(const QJsonValue& jsonValue, int maxLength, int indentLevel) {
@jniemann66
jniemann66 / printJson-old.cpp
Created September 23, 2018 22:47
Old printJson (using string insertion - slow)
QString printJSON(const QJsonValue& jsonValue, int maxLength, int indentLevel) {
static const QString indent{QStringLiteral(" ")};
static const QString cn{QStringLiteral(",\n")};
QString whiteSpace(indent.repeated(indentLevel));
switch(jsonValue.type()) {
case QJsonValue::Object:
{
QStringList values;
QJsonObject o = jsonValue.toObject();
@jniemann66
jniemann66 / longpress.h
Last active June 4, 2020 06:01
Qt: Event Filter for Long Mouse Press (hold mouse for >= 1sec)
// LongPress: event filter Object for detecting Mouse pressed down for 1 second or more
// when triggered, it executes callback function supplied in the constructor
// usage:
/*
someButton->installEventFilter(new LongPress(this, [this] {
// do some stuff
}));
*/