Important: Please read the Qt Code of Conduct -

QResizeEvent alternative for QQuickItem

  • Hello,

    Is there an alternative to QResizeEvent for QQuickItem?

  • Moderators

    Is that what you mean?

    Window {
      onWidthChanged: console.log("New width: " + width)

    However, QResizeEvent comes from QtGui - QML windows also respond to it. You can probably catch the event on C++ side if you need to.

  • @sierdzio I should have specified that I need to catch it on c++ side. I have tried overriding event method and catching QResizeEvent but it was never captured.

    bool Test::event(QEvent *ev)
        if (ev->type() == QEvent::Resize) {
            QResizeEvent *resizeEvent = static_cast<QResizeEvent *>(ev);
            qDebug() << resizeEvent;
            return true;
        return QObject::event(ev);

    method to change size:

    Q_INVOKABLE void incSize();
    void Test::incSize()
        setWidth(width() - 1);
        setHeight(height() - 1);

    qml side, button changes Test's size.

        Test {
            id: tsX
            width: 100.2
            height: 100.2
            y: 2
        Button {
            x: 150
            y: 100
            text: "check2"
            MouseArea {
                anchors.fill: parent
                onClicked: { tsX.incSize() }

  • Moderators

    Resize events happen for windows and widgets, not QQuickItems (I assume Test is a QQuickItem). See the event list from the documentation.

    If you want to catch this from C++ side, you need to connect to height/widthChanged() signal, or reimplenent geometryChanged() slot.

Log in to reply