Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    QML and Qt Quick
    4
    7
    307
    Loading More Posts
    • 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
      mirro last edited by mirro

      1 Reply Last reply Reply Quote -3
      • 6thC
        6thC last edited by

        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 Reply Quote 2
        • M
          mirro last edited by

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

          KroMignon 1 Reply Last reply Reply Quote -1
          • KroMignon
            KroMignon @mirro last edited by

            @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 Reply Quote 0
            • M
              mirro @KroMignon last edited by 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");
              }
              }
              }
              ``
              KroMignon 1 Reply Last reply Reply Quote 0
              • KroMignon
                KroMignon @mirro last edited by

                @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 Reply Quote 2
                • J.Hilk
                  J.Hilk Moderators last edited by

                  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

                  Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post