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. How to reposition a widget when its layout changed
Qt 6.11 is out! See what's new in the release blog

How to reposition a widget when its layout changed

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.1k 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.
  • D Offline
    D Offline
    Dams
    wrote on last edited by
    #1

    I have written a widget A containing among others an horizontal layout containing in turn a widget B. When a particular field of A is clicked, a widget C is created and added to the horizontal layout next to B. Widget A is correctly resized and displayed in this case. But I want to move A if it goes beyond the screen limits because of its new size.
    For that, I wrote a calculatePosition() function returning a QPoint which find a correct position for A. I pass this QPoint to A->move(). This runs well when I call the move() in a dedicated slot, for example onClicked() for a button.
    But what I want is that this repositioning automatically occurs after widget C is added to the layout. And I cannot achieve that!
    You suggestions are welcome.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dams
      wrote on last edited by
      #2

      I have to precise that calculatePosition() is based on A->sizeHint() and that this value is not still updated just after horizontalLayout->addWidget(C)...

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        In that case, why not install an event filter and catch the show event from your widget C and only then do your manipulations ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • D Offline
          D Offline
          Dams
          wrote on last edited by
          #4

          Hi SGaist,

          Sorry for ma late reply. You are right! I used showEvent of my widget C to send a signal and called move(calculatePosition()) to a dedicated slot. And it runs!
          Before posting my question, I tried to use showEvent of widget A, but it is not called when widget C appears.
          Thanks for your help!
          Have a good day.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Because A and C are independent. The fact that C is shown as no influence on the show event of A.

            In any case, since you have it working now, lease mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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