Metadata-Version: 2.4
Name: QtDataTable
Version: 1.0.0
Summary: A reusable, model-view data table widget for PySide6 applications
License-Expression: MIT
Project-URL: Source, https://github.com/Harry-g25/QtDataTable
Project-URL: Issues, https://github.com/Harry-g25/QtDataTable/issues
Project-URL: Documentation, https://github.com/Harry-g25/QtDataTable/tree/master/docs
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: User Interfaces
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: PySide6-Essentials<7,>=6.10
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: mypy>=1.15; extra == "dev"
Requires-Dist: pytest>=8.4; extra == "dev"
Requires-Dist: pytest-qt>=4.5; extra == "dev"
Requires-Dist: ruff>=0.11; extra == "dev"
Requires-Dist: twine>=6.2; extra == "dev"
Provides-Extra: excel
Requires-Dist: openpyxl<4,>=3.1; extra == "excel"
Provides-Extra: benchmark
Requires-Dist: psutil>=5.9; extra == "benchmark"
Dynamic: license-file

# QtDataTable

QtDataTable is a reusable PySide6 widget for displaying and editing business
data. Pass column definitions and rows to get a table with sorting, search,
selection and optional filters. QtDataTable handles the Qt model, proxy and
delegate internally.

## Install

Use Python 3.11 or newer in a virtual environment. QtDataTable installs
PySide6 Essentials as a dependency.

```powershell
python -m pip install QtDataTable
```

Use `"QtDataTable[excel]"` to add Excel export. To install from a source
checkout, run `python -m pip install .` in the project directory.

## Quick start

```python
from PySide6.QtWidgets import QApplication
from qtdatatable import DataTable

app = QApplication([])
table = DataTable(columns=["Name", "Age"], data=[["Alice", 30], ["Bob", 25]])
table.resize(480, 260)
table.show()
app.exec()
```

In an existing app, pass the parent widget to `DataTable(parent, ...)` and add
the table to the parent's layout. Reuse your application's `QApplication`.

## Work with records

Use dictionary rows when the data has stable keys. Column titles are independent
of those keys, and a record can carry extra fields such as a job ID.

```python
from decimal import Decimal

table = DataTable(
    columns=[
        {"key": "customer", "title": "Customer", "stretch": True},
        {"key": "status", "title": "Status", "type": "badge"},
        {"key": "value", "title": "Job value", "type": "currency"},
    ],
    data=[{"job": "J-42", "customer": "Afon", "status": "Pending", "value": Decimal("12.50")}],
    row_key="job",
    filterable=True,
    alternating_rows=True,
)

job_id = table.add_row({"job": "J-43", "customer": "Meridian", "status": "Pending"})
table.update_rows({job_id: {"status": "Completed"}})
table.search("meridian")
table.set_filter("status", "Completed")
table.sort_by("value", ascending=False)
table.select_row(job_id)
job = table.get_row(job_id)
table.row_double_clicked.connect(lambda ident, row: print(ident, row["customer"]))
```

`get_data()` returns independent dictionaries in source order.
`get_data("visible")` returns matching rows in display order. Call
`set_data(rows)` to replace the dataset and `delete_row(job_id)` to remove one
record. Use `get_row_ids()` to enumerate IDs, including IDs generated by
the table, and `delete_rows(ids)` to remove a batch.

## Features and examples

- Click a sortable header to change its sort direction. Use Ctrl or Shift for
  multi-row selection when `selection_mode="multiple"`. Press Alt+Down for
  table actions or Ctrl+Shift+C to copy selected rows.
- Search matches raw text and formatted cell text, ignoring case. Clear a
  column filter with `set_filter(key, None)`. Pass `mode="contains"` for
  substring filtering, or use `set_null_filter()` and `set_range_filter()`
  for explicit predicates.
- Use native Python values with the `text`, `integer`, `number`, `currency`,
  `percentage`, `date`, `datetime`, `boolean` and `badge` types. Currency uses
  major units. Percentages use fractions by default, so `0.25` displays as
  `25%`. Set `percentage_input="points"` to store `25` for `25%`.
- Set `editable=True` and double-click a cell or press F2 to edit. Connect
  `data_changed` to receive the row ID, field key, old and new values. Invalid
  input remains available for correction.
- Use `export_csv("jobs.csv", scope="visible")` for the current view.
  `export_excel()` requires the `excel` extra.
- Set `theme="light"`, `"dark"`, `"auto"` or `"system"`, or pass a
  `ThemeConfig` for custom colours, fonts and density.

Run any example from the checkout after installing the package.

| Example | Demonstrates |
| --- | --- |
| `python examples/basic_table.py` | A table using positional rows |
| `python examples/business_table.py` | A job register with badges, value, due date and progress |
| `python examples/search_filter.py` | Combined search and column filters |
| `python examples/editable_table.py` | Validated edits and feedback |
| `python examples/theme_showcase.py` | Switching themes at runtime |
| `python examples/large_dataset.py` | Browsing 50,000 records |
| `python examples/worker_fetch.py` | Background fetching, cancellation and stale-result handling |

## Troubleshooting

- If you see “Must construct a QApplication before a QWidget,” create
  `QApplication` before the table and retain it for the application's lifetime.
- If values sort alphabetically, check their Python types. Pass `10` and `2`
  for numeric ordering. Convert numbers and dates from file or database strings
  before passing them to the table.
- If a row disappears after an edit, check the active search and column
  filters. Use `get_data()` to inspect all records.
- If an edit is unavailable, check the table and column `editable` settings.
  A configured row-key field is read-only in the UI.

[Getting started](https://github.com/Harry-g25/QtDataTable/blob/master/docs/getting-started.md) ·
[API reference](https://github.com/Harry-g25/QtDataTable/blob/master/docs/api-reference.md) ·
[Customisation](https://github.com/Harry-g25/QtDataTable/blob/master/docs/customisation.md) ·
[Architecture](https://github.com/Harry-g25/QtDataTable/blob/master/docs/architecture.md) ·
[Benchmarks](https://github.com/Harry-g25/QtDataTable/blob/master/docs/benchmarks.md) ·
[Publishing](https://github.com/Harry-g25/QtDataTable/blob/master/docs/publishing.md)

QtDataTable is MIT-licensed. PySide6 has its own distribution terms.
[QtDataTable licence](https://github.com/Harry-g25/QtDataTable/blob/master/LICENSE) ·
[Qt for Python licensing](https://doc.qt.io/qtforpython-6/commercial/index.html)
