Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is there a direct function that would allow "locking" a widgets' positions to another widget?
Forum Updated to NodeBB v4.3 + New Features

Is there a direct function that would allow "locking" a widgets' positions to another widget?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 422 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.
  • Dummie1138D Offline
    Dummie1138D Offline
    Dummie1138
    wrote on last edited by
    #1

    Hi. I have two QWidgets, one a QFrame built to be a vertical bar, the other a QLabel, as shown here.

    d8475853-1249-4434-bee3-5f836fb948c0-image.png

    I was wondering whether there was a way to directly "lock" the positions of the two widgets together, such that the QLabel would move with the QFrame when the QFrame is repositioned, without having to also manually reposition the QLabel with a move function. Parenting the QLabel to the QFrame just puts the QLabel within the QFrame, which basically hides the QFrame.

    Please let me know if more information is required, I hope I have explained my issue adequately.

    JonBJ J.HilkJ 2 Replies Last reply
    0
    • Dummie1138D Dummie1138

      Hi. I have two QWidgets, one a QFrame built to be a vertical bar, the other a QLabel, as shown here.

      d8475853-1249-4434-bee3-5f836fb948c0-image.png

      I was wondering whether there was a way to directly "lock" the positions of the two widgets together, such that the QLabel would move with the QFrame when the QFrame is repositioned, without having to also manually reposition the QLabel with a move function. Parenting the QLabel to the QFrame just puts the QLabel within the QFrame, which basically hides the QFrame.

      Please let me know if more information is required, I hope I have explained my issue adequately.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Dummie1138
      So far as I know, the easiest way to do this is to define a QWidget as the parent and put the QFrame and the QLabel on it. Then you move the parent QWidget and it takes its children with it.

      1 Reply Last reply
      2
      • Dummie1138D Dummie1138

        Hi. I have two QWidgets, one a QFrame built to be a vertical bar, the other a QLabel, as shown here.

        d8475853-1249-4434-bee3-5f836fb948c0-image.png

        I was wondering whether there was a way to directly "lock" the positions of the two widgets together, such that the QLabel would move with the QFrame when the QFrame is repositioned, without having to also manually reposition the QLabel with a move function. Parenting the QLabel to the QFrame just puts the QLabel within the QFrame, which basically hides the QFrame.

        Please let me know if more information is required, I hope I have explained my issue adequately.

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @Dummie1138 usually parenting works, as the position of the child is always relative to the parent.

        but since that "doesn't work" let me introduce you to c++ property bindings
        https://doc-snapshots.qt.io/qt6-dev/bindableproperties.html

        hell of a lot more complicated/complex but it should enable you to "lock" siblings position together without doing it manually


        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.

        JonBJ 1 Reply Last reply
        0
        • J.HilkJ J.Hilk

          @Dummie1138 usually parenting works, as the position of the child is always relative to the parent.

          but since that "doesn't work" let me introduce you to c++ property bindings
          https://doc-snapshots.qt.io/qt6-dev/bindableproperties.html

          hell of a lot more complicated/complex but it should enable you to "lock" siblings position together without doing it manually

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @J-Hilk
          Ah, so I read there

          Bindable properties allow to achieve the same not only in QML code, but also in C++.

          So you can utilise the QML ability to monitor changes and change things for you this way, right? In this solution you would "bind" the (x,y) coordinates of the label to those of the frame, so if the frame is moved the label moves with it? Would the frame be bound to the label, so if the label moves the frame does too, or would that create a "binding loop" problem?

          J.HilkJ 1 Reply Last reply
          0
          • JonBJ JonB

            @J-Hilk
            Ah, so I read there

            Bindable properties allow to achieve the same not only in QML code, but also in C++.

            So you can utilise the QML ability to monitor changes and change things for you this way, right? In this solution you would "bind" the (x,y) coordinates of the label to those of the frame, so if the frame is moved the label moves with it? Would the frame be bound to the label, so if the label moves the frame does too, or would that create a "binding loop" problem?

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @JonB said in Is there a direct function that would allow "locking" a widgets' positions to another widget?:

            or would that create a "binding loop" problem?

            it would! You should only bind one to an other, not both to each other :D


            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
            0

            • Login

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