aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qtpy2cpp_lib/tests/baseline/basic_test.cpp
blob: 8ee7be31ee9aad982f3099315c514fa0dd3fbc9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

// Converted from basic_test.py
#include <QtCore/Qt>
#include <QtGui/QColor>
#include <QtGui/QPainter>
#include <QtGui/QPaintEvent>
#include <QtGui/QShortcut>
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>

class Window : public QWidget
{
public:

    Window(QWidget * parent = nullptr)
    {
        super()->__init__(parent);
    }

    void paintEvent(QPaintEvent * e)
    {
        paint("bla");
    }

    void paint(const QString & what, color = Qt::blue)
    {
        { // Converted from context manager
            p = QPainter();
            p->setPen(QColor(color));
            rect = rect();
            w = rect->width();
            h = rect->height();
            p->drawLine(0, 0, w, h);
            p->drawLine(0, h, w, 0);
            p->drawText(rect->center(), what);
        }
    }

    void sum()
    {
        values = {1, 2, 3};
        result = 0;
        for (v: values) {
            result += v
        }
        return result;
    }
};

int main(int argc, char *argv[])
{
    QApplication app(sys->argv);
    window = Window();
    auto *sc = new QShortcut((Qt::CTRL | Qt::Key_Q), window);
    sc->activated->connect(window->close);
    window->setWindowTitle("Test");
    window->show();
    sys->exit(app.exec());
    return 0;
}