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 auto-size dialog depending on which "stack" is front?
Forum Updated to NodeBB v4.3 + New Features

how to auto-size dialog depending on which "stack" is front?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 1.5k Views 3 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
    davecotter
    wrote on last edited by
    #1

    i have a dialog with a QStackedWidget, i switch between them with a QListWidget. I'd like the dialog to auto-size itself (animated wooshing a bonus!) based on which stack is "front". I've put vertical Spacers at the bottom of each stack, to top-justify each stack, but i'd rather resize the dialog. here's a couple stacks:

    1_1560968653916_Screen Shot 2019-06-19 at 11.22.42 AM.png

    0_1560968653915_Screen Shot 2019-06-19 at 11.22.36 AM.png

    2_1560968653916_Screen Shot 2019-06-19 at 11.22.48 AM.png

    as you can see, the LAST one is the tallest one, which currently defines the minimum size of the dialog.

    Is there a way to, when the user causes a stack to come to front, tell the dialog to minimize it's vertical size based on the front stack?

    -dave

    kshegunovK 1 Reply Last reply
    0
    • D Offline
      D Offline
      davecotter
      wrote on last edited by
      #9

      this is what worked:

      QWidget		*pageP;
      
      for (int i = 0; i < stackP->count (); ++i) {
      	pageP = stackP->widget(i);
      	pageP->setSizePolicy(
      		QSizePolicy::Preferred, 
      		QSizePolicy::Ignored);
      }
      
      pageP = stackP->widget(stackIndexL);
      pageP->setSizePolicy(
      	QSizePolicy::Preferred, 
      	QSizePolicy::Preferred);
      
      stackP->adjustSize();
      adjustSize();
      
      1 Reply Last reply
      2
      • D davecotter

        i have a dialog with a QStackedWidget, i switch between them with a QListWidget. I'd like the dialog to auto-size itself (animated wooshing a bonus!) based on which stack is "front". I've put vertical Spacers at the bottom of each stack, to top-justify each stack, but i'd rather resize the dialog. here's a couple stacks:

        1_1560968653916_Screen Shot 2019-06-19 at 11.22.42 AM.png

        0_1560968653915_Screen Shot 2019-06-19 at 11.22.36 AM.png

        2_1560968653916_Screen Shot 2019-06-19 at 11.22.48 AM.png

        as you can see, the LAST one is the tallest one, which currently defines the minimum size of the dialog.

        Is there a way to, when the user causes a stack to come to front, tell the dialog to minimize it's vertical size based on the front stack?

        -dave

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #2

        @davecotter said in how to auto-size dialog depending on which "stack" is front?:

        Is there a way to, when the user causes a stack to come to front, tell the dialog to minimize it's vertical size based on the front stack?

        If I'm not wrong, setting the resize policy of the dialog to QSizePolicy::MinimumExpanding and calling QWidget::adjustSize after you switched the stack widget might do the trick.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        0
        • D Offline
          D Offline
          davecotter
          wrote on last edited by
          #3

          i've set the size policy on the QDialog widget like this:
          0_1560978050927_Screen Shot 2019-06-19 at 2.00.34 PM.png

          and here is my code:

          0_1560977966865_Screen Shot 2019-06-19 at 1.56.31 PM.png

          if I un-comment that adjustSize(); line, then my dialog gets much WIDER, and does not get shorter.

          it seems that it is finding the minimum size of ALL stack panels, and using that, instead of only finding the minimum size of the CURRENT (front most) stack panel?

          kshegunovK 1 Reply Last reply
          0
          • D davecotter

            i've set the size policy on the QDialog widget like this:
            0_1560978050927_Screen Shot 2019-06-19 at 2.00.34 PM.png

            and here is my code:

            0_1560977966865_Screen Shot 2019-06-19 at 1.56.31 PM.png

            if I un-comment that adjustSize(); line, then my dialog gets much WIDER, and does not get shorter.

            it seems that it is finding the minimum size of ALL stack panels, and using that, instead of only finding the minimum size of the CURRENT (front most) stack panel?

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #4

            Eh, I may be wrong, that's tricky. What I'd suggest you try is to remove the vertical stretches and set the policy of each of the stacked widgets to Minimum. If that doesn't do it, I'm out of ideas.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0
            • D Offline
              D Offline
              davecotter
              wrote on last edited by
              #5

              yep nope. seems the minimum size of the dialog is determined by the stack panel with the maximum size, not the stack panel that is in front. i do not see a way around it.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                davecotter
                wrote on last edited by
                #6

                can anyone contradict that? i don't yet have access to debugging the source code so i can't tell if there's a way out of this

                kshegunovK 1 Reply Last reply
                0
                • D davecotter

                  can anyone contradict that? i don't yet have access to debugging the source code so i can't tell if there's a way out of this

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #7

                  If you prepare a simplistic compileable example that reproduces it, I can run it through on Linux.

                  Read and abide by the Qt Code of Conduct

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

                    Hi,

                    Take a look at this stack overflow thread. It shows a technique to achieve what you want.

                    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
                    1
                    • D Offline
                      D Offline
                      davecotter
                      wrote on last edited by
                      #9

                      this is what worked:

                      QWidget		*pageP;
                      
                      for (int i = 0; i < stackP->count (); ++i) {
                      	pageP = stackP->widget(i);
                      	pageP->setSizePolicy(
                      		QSizePolicy::Preferred, 
                      		QSizePolicy::Ignored);
                      }
                      
                      pageP = stackP->widget(stackIndexL);
                      pageP->setSizePolicy(
                      	QSizePolicy::Preferred, 
                      	QSizePolicy::Preferred);
                      
                      stackP->adjustSize();
                      adjustSize();
                      
                      1 Reply Last reply
                      2

                      • Login

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