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. Is there any other method to resize the controls like "OnWidthChanged()" dose in QML?
QtWS25 Last Chance

Is there any other method to resize the controls like "OnWidthChanged()" dose in QML?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 4 Posters 1.0k Views
  • 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.
  • M Offline
    M Offline
    mirro
    wrote on last edited by mirro
    #1
    1 Reply Last reply
    -3
    • 6thC6 Offline
      6thC6 Offline
      6thC
      wrote on last edited by
      #2

      onWidthChanged doesn't resize anything. It's a signal that fires after the fact.

      I suspect you would like to be aware of layouts and anchors... but perhaps you maybe wish to ask that question again?

      Low effort questions are almost, if not, insulting to people who are putting in effort in for free to genuinely try and be helpful, the least you can do it try as well.

      1 Reply Last reply
      2
      • M Offline
        M Offline
        mirro
        wrote on last edited by
        #3

        @6thC said in Is there any other method to resize the controls like "OnWidthChanged()" dose in QML?:

        onWidthChanged doesn't resize anything. It's a signal that fires after the fact.
        I suspect you would like to be aware of layouts and anchors... but perhaps you maybe wish to ask that question again?

        no layouts and anchors.I would like to know those signals QML.Controls notifying the change in size.

        KroMignonK 1 Reply Last reply
        -1
        • M mirro

          @6thC said in Is there any other method to resize the controls like "OnWidthChanged()" dose in QML?:

          onWidthChanged doesn't resize anything. It's a signal that fires after the fact.
          I suspect you would like to be aware of layouts and anchors... but perhaps you maybe wish to ask that question again?

          no layouts and anchors.I would like to know those signals QML.Controls notifying the change in size.

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #4

          @mirro said in Is there any other method to resize the controls like "OnWidthChanged()" dose in QML?:

          no layouts and anchors.I would like to know those signals QML.Controls notifying the change in size.

          Can you please explain what is the problem you try to solve?
          I don't understand what you are asking for, so I can not help you.

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          M 1 Reply Last reply
          0
          • KroMignonK KroMignon

            @mirro said in Is there any other method to resize the controls like "OnWidthChanged()" dose in QML?:

            no layouts and anchors.I would like to know those signals QML.Controls notifying the change in size.

            Can you please explain what is the problem you try to solve?
            I don't understand what you are asking for, so I can not help you.

            M Offline
            M Offline
            mirro
            wrote on last edited by mirro
            #5

            @KroMignon

            How does quickwidget correctly get geometric information from QML in C++.

            The Rectangle geometry fom QML that I get in the resizeEvent() event is null value.

            import QtQuick 2.7
            import QtQuick.Controls 2.0
            
            Item {
                id:view
                visible: true
                Rectangle{
                     id:rct
                     objectName:"Rct"
                     anchors.fill: parent
                     color:'red'
                 }
            }
            
            
            
            
            class cusQQuickWidget:public QuickWidget{
            Q_OBJECT
            public:
            cusQQuickWidget(QWidget* parent = nullptr):QuickWidget(parent){}
            virtual ~cusQQuickWidget(){}
            protected:
            void resizeEvent(QResizeEvent* p)
            {
            QQuickWidget::resizeEvent(p);
            //
            QQuickItem* pItem = rootObject();
            QObject rect = pItem->findChild<QObject>("Rct");
            if (rect)
            {
            //All is null value
            QVariant x = rect->property("x");
            QVariant x = rect->property("y");
            QVariant wid = rect->property("width");
            QVariant hei = rect->property("height");
            }
            }
            }
            ``
            KroMignonK 1 Reply Last reply
            0
            • M mirro

              @KroMignon

              How does quickwidget correctly get geometric information from QML in C++.

              The Rectangle geometry fom QML that I get in the resizeEvent() event is null value.

              import QtQuick 2.7
              import QtQuick.Controls 2.0
              
              Item {
                  id:view
                  visible: true
                  Rectangle{
                       id:rct
                       objectName:"Rct"
                       anchors.fill: parent
                       color:'red'
                   }
              }
              
              
              
              
              class cusQQuickWidget:public QuickWidget{
              Q_OBJECT
              public:
              cusQQuickWidget(QWidget* parent = nullptr):QuickWidget(parent){}
              virtual ~cusQQuickWidget(){}
              protected:
              void resizeEvent(QResizeEvent* p)
              {
              QQuickWidget::resizeEvent(p);
              //
              QQuickItem* pItem = rootObject();
              QObject rect = pItem->findChild<QObject>("Rct");
              if (rect)
              {
              //All is null value
              QVariant x = rect->property("x");
              QVariant x = rect->property("y");
              QVariant wid = rect->property("width");
              QVariant hei = rect->property("height");
              }
              }
              }
              ``
              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by
              #6

              @mirro said in Is there any other method to resize the controls like "OnWidthChanged()" dose in QML?:

              How does quickwidget correctly get geometric information from QML in C++.

              I suppose you are loading the QML into your custom QuickWidget, but you did never set the width and height from your top element, so they are 0!
              Simply change your QML to set width and height like this:

              import QtQuick 2.7
              import QtQuick.Controls 2.0
              
              Item {
                  id:view
                  visible: true
              
                  width: parent.width
                  height: parent.height
                 
                  Rectangle{
                      id:rct
                      objectName:"Rct"
                      anchors.fill: parent
                      color:'red'
                  }
              }
              
              

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              1 Reply Last reply
              2
              • J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                alternatively, use setResizeMode of your QQuickWidget and set it to SizeRootObjectToView, may solve all your issues.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                1

                • Login

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