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. [SOLVED] Help with size policy docked vs. undocked
QtWS25 Last Chance

[SOLVED] Help with size policy docked vs. undocked

Scheduled Pinned Locked Moved Solved General and Desktop
sizepolicydockwidget
8 Posts 2 Posters 2.9k Views
  • 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.
  • P Offline
    P Offline
    pmh4514
    wrote on 3 Mar 2016, 14:13 last edited by pmh4514 3 Mar 2016, 15:10
    #1

    I have a widget which contains only a single FrameWidget (onto which I draw a graphic, but that's not important for this discussion)

    This widget can be docked into the main window.

    When it is docked, I would like to ensure that the FrameWidget is a fixed 300x300 px.. But when the user undocks it, I'd like to ensure that the FrameWidget expands to fill the size they make the undocked window..

    How can I make it behave like this? If I set it fixed, when undocked, the FrameWidget stays at 300x300 regardless the size the user makes the window.. If I set it to preferred or expanding, it works as I'd like while undocked, but when docked it fills the space, rather than being the fixed 300x300.

    Thanks!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 3 Mar 2016, 14:22 last edited by
      #2

      You can connect to the topLevelChanged signal of the dock and change the policy for docked or undocked state there.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pmh4514
        wrote on 3 Mar 2016, 14:42 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • P Offline
          P Offline
          pmh4514
          wrote on 3 Mar 2016, 14:49 last edited by
          #4

          actually I found that if I leave the size policy at maximum in both directions, when I trap the topLevelChanged signal I can then change the maximum height and width values, and get the desired effect. (it I'm not toggling the size policy, rather, specifying new max height and width values.)

          seems to work, but "Feels like" it's not the right Qt way..

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on 3 Mar 2016, 15:02 last edited by
            #5

            Every widget has its own policy, so you can apply it to whatever you want. In your case you want to control the size of the frame so set the policy on the frame, i.e. something like this:

            connect(theDock, &QDockWidget::topLevelChanged, someObject, &SomeClass::someAdjustPolicyFunc);
            
            
            SomeClass::someAdjustPolicyFunc(bool topLevel)
            {
               if (topLevel)
                  someImageFrame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
               else
                  someImageFrame->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
            }
            
            
            1 Reply Last reply
            1
            • P Offline
              P Offline
              pmh4514
              wrote on 3 Mar 2016, 15:10 last edited by
              #6

              Thank you, I have it working now.

              PS - your connect statement looks different to me, is that a new way in v5? (ie. where is SIGNAL and SLOT specifier?

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on 3 Mar 2016, 15:14 last edited by
                #7

                Yes, starting with Qt5 there's a new connect syntax with no macros (yay!). I highly recommend switching to it, if not just for the compile time type and parameter checking it does. More info here.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  pmh4514
                  wrote on 3 Mar 2016, 15:30 last edited by
                  #8

                  very cool. I like it!

                  thanks again

                  1 Reply Last reply
                  0

                  1/8

                  3 Mar 2016, 14:13

                  • Login

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