# 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))
    ]
)
```
