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 have a QDockWidget with auto adjusted size?
Qt 6.11 is out! See what's new in the release blog

How to have a QDockWidget with auto adjusted size?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.6k Views 4 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.
  • A Offline
    A Offline
    Alain38 0
    wrote on last edited by
    #1

    Hi,
    In my application I have a QDockWidget. Inside the QDockWidget I have various widgets. Some of them changes dynamically their size.

    My problem now is when the QDockWidget is undocked. In floating mode I want that it always takes the minimum possible size. So, what I did (using the topLevelChanged() signal) is to call adjustSize() when it becomes floating. This works well.

    When I performs an action that increases the size of an internal widget, the size of the QDockWidget automatically increases too. That is what I want.

    But, when the action reduces the size of the internal widget, the size of the QDockWIdget does not follows. And this NOT what I want.

    So, do you know how to force the QDockWidget too always adjust its size to the internal content?

    Thanks.

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

      Hi,

      Can you show the method's implementation ?

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

      A 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Can you show the method's implementation ?

        A Offline
        A Offline
        Alain38 0
        wrote on last edited by
        #3

        Hi @SGaist ,
        I implemented almost nothing. Currently I'm just using QDockWidget. The only code I have added is to connect the signal topLevelChanged() that calls adjustSize() on the QDockWidget when the parameter is "true". So, this reduces the size of the floating QDockWidget to the expected one. But it is just a "one-shot" operation (when the widget becomes floating).

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

          Then what can trigger a widget size reduction ?

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

          A 1 Reply Last reply
          1
          • SGaistS SGaist

            Then what can trigger a widget size reduction ?

            A Offline
            A Offline
            Alain38 0
            wrote on last edited by
            #5

            Hi @SGaist,
            This is exactly my problem. As, in the QDockWidget I have a complex hierarchy of widgets, that can be changed programmatically, I do not know how to manage the fact that a widget has disappeared (removed or just hidden). I expected to have something with the size policies. But I did not found a combination of size policies that performs what I want. At least in the case of reduction size.

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              hi
              But you do use layout in the QDockWidget via setWidget and apply layout to that
              to hold the various widgets that you hide and show etc ?

              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