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. How to reset anchors?
Forum Updated to NodeBB v4.3 + New Features

How to reset anchors?

Scheduled Pinned Locked Moved QML and Qt Quick
11 Posts 4 Posters 8.5k 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.
  • Z Offline
    Z Offline
    ZapB
    wrote on last edited by
    #2

    I think you need to explicitly state which item you are changing anchors on with something like this in a state.

    @
    AnchorChanges {
    target: icon
    anchors.bottom: undefined
    }
    @

    You onPressed: handler can then simply change to that state. Does that work for you?

    Nokia Certified Qt Specialist
    Interested in hearing about Qt related work

    1 Reply Last reply
    0
    • F Offline
      F Offline
      franziss
      wrote on last edited by
      #3

      Thank you very much for your help ZapB, I implemented a state and use AnchorChanges, it works now.

      Is it possible to do anchor changes in c++, instead of qml?

      H 1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on last edited by
        #4

        Hmmm, good question. I'm not sure. It's not something I have ever tried. In theory I would think yes as the anchors are just properties like everything else. Have a play around with it and see if it is possible. I would be interested to hear the outcome of your experiments.

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply
        0
        • F Offline
          F Offline
          franziss
          wrote on last edited by
          #5

          I tried the following slot, which is called when I move an object (e.g. icon) into a slide (e.g. rectangle). Once the object is in the slide, I want to set the object as a child of the slide, so that when I drag the slide, the object will move with it.

          In this function, both slide and object are cast as QGraphicsWidgets and then I try to use QGraphicsAnchorLayout to anchor the object inside slide, but it does not work.

          @
          void cc::putObjectIntoSlide(QGraphicsObject * slide, QGraphicsObject * object)
          {
          if (object != NULL)
          {
          qDebug("got object in slide");
          object->setParent(slide);
          QGraphicsWidget *a = new QGraphicsWidget(slide);
          QGraphicsWidget *b = new QGraphicsWidget(object);
          QGraphicsAnchorLayout *la = new QGraphicsAnchorLayout;
          QGraphicsAnchorLayout *lb = new QGraphicsAnchorLayout;
          a->setLayout(la);
          b->setLayout(lb);
          la->addAnchor(la, Qt::AnchorBottom, lb, Qt::AnchorBottom);
          }
          else
          {
          qDebug("no object");
          }
          }
          @

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZapB
            wrote on last edited by
            #6

            QGraphicsAnchorLayout has nothing to do with anchors in QML. I'm not sure if the QML anchors are exported in any useable way in C++ other than perhaps by way of the setProperty() and property() functions of QObject.

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            0
            • F Offline
              F Offline
              franziss
              wrote on last edited by
              #7

              Ok, I tried using setProperty as follows, but it doesn't work

              @
              object->setProperty("anchors.bottom","parent.bottom");
              @

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #8

                I'd think that anchors is actually an object (or some other collection of properties) of its own, so I am not surprised that that doesn't work. No idea how it would work though.

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  franziss
                  wrote on last edited by
                  #9

                  If I drag an object A into object B, and make object A a child of object B, how do I anchor A to B?

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    Hit Tiger Tonight
                    wrote on last edited by
                    #10

                    @franziss said in How to reset anchors?:

                    Thank you very much for your help ZapB, I implemented a state and use AnchorChanges, it works now.

                    Is it possible to do anchor changes in c++, instead of qml?

                    Yes, you can. Please refer to: https://forum.qt.io/topic/143222/how-to-pass-an-object-ref-from-c-to-qml

                    1 Reply Last reply
                    0
                    • F franziss

                      Thank you very much for your help ZapB, I implemented a state and use AnchorChanges, it works now.

                      Is it possible to do anchor changes in c++, instead of qml?

                      H Offline
                      H Offline
                      Hit Tiger Tonight
                      wrote on last edited by
                      #11

                      @franziss said in How to reset anchors?:

                      Thank you very much for your help ZapB, I implemented a state and use AnchorChanges, it works now.

                      Is it possible to do anchor changes in c++, instead of qml?

                      Yes, you can. Please refer to: https://forum.qt.io/topic/143222/how-to-pass-an-object-ref-from-c-to-qml

                      1 Reply Last reply
                      0

                      • Login

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