# Widgets

## Usage

As you know in `PySide6.QtWidgets` there are set, get, and add functions, so when you write the name of a function of type `set` or `add` in the `**kwargs`, that function will be executed with the value inserted.

```python
from Qtica.widgets import Widget
from Qtica.utils import Args

Widget(
    setWindowTitle: Args | Any = "Window Title",
    addAction: list[Args | Any] = QAction()
)
```

### to overwrite widget events you can use the events parameter

```python
Widget(
    events=[
        ("Event Name", lambda e: ...)
        # Using enums.Events
        (Events.mousePress, lambda e: ...)
    ]
)
```

### to connect widget signals you can use the `signals` parameter

```python
Widget(
    signals=[
        ("Signal Name", lambda: ...)
        # Using enums.Signals
        (Signals.clicked, lambda: ...)
    ]
)
```

### to write inline Qt Style Sheet

{% tabs %}
{% tab title="Using Dict" %}

```python
Widget(
    qss={
        "background-color": "purple",
        "font-size": "12px",
        "color": "white"
    }
)
```

{% endtab %}

{% tab title="Using QStyleSheet" %}

```python
Widget(
    qss=QStyleSheet(
        qss={
            "background-color": "--bg-color",
            "font-size": "12px",
            "color": "--fg-color"
        },
        vars={
            "bg-color": "purple",
            "fg-color": "white"
        }
    )
)
```

{% endtab %}
{% endtabs %}

### the long press signal usage

```python
Widget(
    long_press_delay: int = 1000,
    signals=[
        ("long_pressed", lambda: print("Long Press Active"))
    ]
)
```

### set window attributes

```python
Widget(
    attrs: Union[list[Qt.WidgetAttribute], dict[Qt.WidgetAttribute, bool]] = None
)
```

### set window flags

```python
Widget(
    flags: Union[list[Qt.WindowType], dict[Qt.WindowType, bool]] = None
)
```

### run class method

```python
Widget(
    methods = [
        ("resize", QSize(200, 200)),
        # Using Func class
        Func("resize", 200, 200),
        # Using Args class
        ("resize", Args(200, 200))
    ]
)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://qticaproject.gitbook.io/qtica/reference/library-reference/widgets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
