Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QResizeEvent alternative for QQuickItem
Qt 6.11 is out! See what's new in the release blog

QResizeEvent alternative for QQuickItem

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eligijus
    wrote on last edited by
    #1

    Hello,

    Is there an alternative to QResizeEvent for QQuickItem?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      E 1 Reply Last reply
      0
      • sierdzioS sierdzio

        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.

        E Offline
        E Offline
        Eligijus
        wrote on last edited by
        #3

        @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.
        Code:

        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() }
                }
            }
        
        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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.

          (Z(:^

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved