Skip to main content

A flexible toolset to improve QML coding experience for PySide6 development.

Project description

LK QtQuick Scaffold

Using Python and Qt QML to build desktop applications from a series of predefined tools.

How to Install

pip install lk-qtquick-scaffold

Python 3.8 is the minimum required version.

Highlights

  • A layout engine to extend QML layouts.
  • Integrate qt logging with python console (no need to enable "emulate terminal in output console" in PyCharm).
  • Executing Python snippet in QML, and vice versa.
  • Easy-to-use register handler for registering Python functions to QML side.
  • Hot loader for testing target layout.
  • Assets manager to thoroughly control application appearance (color, motion, shape, typograph, and so on).
  • A built-in theme to quickly produce elegant user interface. For example, use LCButton or LCGhostButton to replace the normal Button.
    • Currently (v1.x) there's only one theme (LightClean Theme) provided.

Feature Quickview

Layout Engine

import QtQuick

Item {
    Rectangle {
        Component.onCompleted: {
            LKLayoutHelper.quick_anchors(this, parent, {
                'reclines': [1, 1, 0, 1], // left, top, right, bottom
                'margins': [12, 4, 12, 4] // left, top, right, bottom
            })
        }
    }
}
import QtQuick

Row {
    spacing: 4
    
    Rectangle {
        width: 0.5 // 50% of parent.width (respect parent.spacing)
        height: parent.height
    }
    
    Rectangle {
        width: 0.2 // 20% of parent.width (respect parent.spacing)
        height: parent.height
    }
    
    Rectangle {
        width: 0 // fill the rest (30% of parent.width) (respect parent.spacing)
        height: parent.height
    }
    
    Component.onCompleted: {
        LKLayoutHelper.hadjust_children_size(this)
    }
}

TODO:MoreExamples

Integrate qt logging with python console

Executing Python snippet in QML, and vice versa

from lk_qtquick_scaffold import eval_js

def foo(a: QObject, b: QObject):
    eval_js('''
        {0}.anchors.left = Qt.binding(() => {{
            return {1}.anchors.left
        }})
    ''', a, b)
import QtQuick

ListView {
    model: pyside.eval(`
        import os
        files = os.listdir(input('target folder: '))
        return files
    `)
}

Register Python functions to QML side

There're two ways to register:

from lk_qtquick_scaffold import reg

@reg()
def foo(*args, **kwargs):
    print(args, kwargs)
    return True
from lk_qtquick_scaffold import pyside

def foo(*args, **kwargs):
    print(args, kwargs)
    return True

pyside.register(foo)

Then call it by function name in QML side:

import QtQuick

Item {
    Component.onCompleted: {
        var result = pyside.call('foo', [1, 2, 3], {'aaa': 4, 'bbb': 5})
    }
}

Hot Loader

from lk_qtquick_scaffold import app, hot_loader

# Just replace `app.start` with `hot_loader.start`
# app.start('view.qml')
hot_loader.start('view.qml')

Assets Manager

TODO:AssetsManagerExample

LightClean Theme

See also code_examples/eg01_viscous_indicator_anim:

import QtQuick
import LightClean
import LightClean.LCComplex

LCWindow {
    width: 280
    height: 360

    LCSideBar {
        anchors.fill: parent

        // icon from: https://iconduck.com/sets/bubblecons-nations-icon-set
        p_model: [
            {m_title: 'Sprint', m_icon: 'file:stopwatch.svg'},
            {m_title: 'Boomerang', m_icon: 'file:boomerang.svg'},
            {m_title: 'Football', m_icon: 'file:football-spain.svg'},
        ]
    }
}

In this example, LCSideBar uses a simple model struct to generate items. Each item has apperance in different status (hovered, selected, etc.), an indicator moves when selection changed.

More screenshots

TODO:AddMoreWidgetsDemo

Working in Progress

  • The documentation is far away to ready status.
  • LightClean Theme is found in Sept. 2020, but it is under refactoring in recent months.
    • The documentation is not provided. You have to check its source code for more infomation.
    • Some old widgets have bugs unfixed.
  • The registered functions by @reg() or pyside.register() are not Slot functions. So it may cause GUI latency on doing heavy task. (It will be resolved in future releases.)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lk-qtquick-scaffold-1.2.1.tar.gz (42.4 kB view hashes)

Uploaded Source

Built Distribution

lk_qtquick_scaffold-1.2.1-py3-none-any.whl (70.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page