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 can I programmatically make a dialog as small as possible?

How can I programmatically make a dialog as small as possible?

Scheduled Pinned Locked Moved Solved General and Desktop
dialog boxlayout issues
6 Posts 4 Posters 745 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.
  • J Offline
    J Offline
    jdent
    wrote on 20 Mar 2024, 18:35 last edited by
    #1

    Hi,

    I have a dialog class drawn all from code - not using ui files. I want to resize it to the smallest dimensions that will still show the contained widgets. I have this in my constructor:

    QVBoxLayout* layout = new QVBoxLayout;
        layout->addWidget(inputWidgetBox);
        layout->addWidget(buttonBox);
        setLayout(layout);
    

    I thought adding this would accomplish my intentions:

        layout->setSizeConstraint(QLayout::SetMinimumSize);
    

    But it does not.
    There must be a function somewhere to make the dialog as small as possible!! Which is it?
    I can resize it with my mouse and see there is a minimum - that's what I want!

    Regards,
    Juan

    R J 2 Replies Last reply 20 Mar 2024, 18:53
    0
    • J JonB
      20 Mar 2024, 19:06

      @jdent said in How can I programmatically make a dialog as small as possible?:

      layout->setSizeConstraint(QLayout::SetMinimumSize);

      If this were to work at all it would actually need to be SetMaximumSize!

      But I think doing it on a layout won't achieve anything. I think you need to do it on the widget, i.e. the QDialog.

      I'll be honest and say that after years I still don't get layouts & sizes & size policies! :( If you do something like dialog->resize(1, 1) or dialog->resize(minimumSize()) does that work?

      M Offline
      M Offline
      mpergand
      wrote on 20 Mar 2024, 19:24 last edited by
      #5

      @JonB said in How can I programmatically make a dialog as small as possible?:

      dialog->resize(minimumSize()) does that work?

      Works for me if resized after show();

      J 1 Reply Last reply 20 Mar 2024, 19:30
      2
      • J jdent
        20 Mar 2024, 18:35

        Hi,

        I have a dialog class drawn all from code - not using ui files. I want to resize it to the smallest dimensions that will still show the contained widgets. I have this in my constructor:

        QVBoxLayout* layout = new QVBoxLayout;
            layout->addWidget(inputWidgetBox);
            layout->addWidget(buttonBox);
            setLayout(layout);
        

        I thought adding this would accomplish my intentions:

            layout->setSizeConstraint(QLayout::SetMinimumSize);
        

        But it does not.
        There must be a function somewhere to make the dialog as small as possible!! Which is it?
        I can resize it with my mouse and see there is a minimum - that's what I want!

        Regards,
        Juan

        R Offline
        R Offline
        Ronel_qtmaster
        wrote on 20 Mar 2024, 18:53 last edited by
        #2

        @jdent use resize(width, height)

        J 1 Reply Last reply 20 Mar 2024, 19:23
        0
        • J jdent
          20 Mar 2024, 18:35

          Hi,

          I have a dialog class drawn all from code - not using ui files. I want to resize it to the smallest dimensions that will still show the contained widgets. I have this in my constructor:

          QVBoxLayout* layout = new QVBoxLayout;
              layout->addWidget(inputWidgetBox);
              layout->addWidget(buttonBox);
              setLayout(layout);
          

          I thought adding this would accomplish my intentions:

              layout->setSizeConstraint(QLayout::SetMinimumSize);
          

          But it does not.
          There must be a function somewhere to make the dialog as small as possible!! Which is it?
          I can resize it with my mouse and see there is a minimum - that's what I want!

          Regards,
          Juan

          J Offline
          J Offline
          JonB
          wrote on 20 Mar 2024, 19:06 last edited by
          #3

          @jdent said in How can I programmatically make a dialog as small as possible?:

          layout->setSizeConstraint(QLayout::SetMinimumSize);

          If this were to work at all it would actually need to be SetMaximumSize!

          But I think doing it on a layout won't achieve anything. I think you need to do it on the widget, i.e. the QDialog.

          I'll be honest and say that after years I still don't get layouts & sizes & size policies! :( If you do something like dialog->resize(1, 1) or dialog->resize(minimumSize()) does that work?

          M 1 Reply Last reply 20 Mar 2024, 19:24
          3
          • R Ronel_qtmaster
            20 Mar 2024, 18:53

            @jdent use resize(width, height)

            J Offline
            J Offline
            jdent
            wrote on 20 Mar 2024, 19:23 last edited by
            #4

            @Ronel_qtmaster Not exactly what I am looking for. I want the dialog to be as small as possible. Can I query the widgets to find their size? and perhaps add the sizes to obtain the minimum size?
            how can I iterate over all the children of a QWidget? maybe this could help...

            1 Reply Last reply
            0
            • J JonB
              20 Mar 2024, 19:06

              @jdent said in How can I programmatically make a dialog as small as possible?:

              layout->setSizeConstraint(QLayout::SetMinimumSize);

              If this were to work at all it would actually need to be SetMaximumSize!

              But I think doing it on a layout won't achieve anything. I think you need to do it on the widget, i.e. the QDialog.

              I'll be honest and say that after years I still don't get layouts & sizes & size policies! :( If you do something like dialog->resize(1, 1) or dialog->resize(minimumSize()) does that work?

              M Offline
              M Offline
              mpergand
              wrote on 20 Mar 2024, 19:24 last edited by
              #5

              @JonB said in How can I programmatically make a dialog as small as possible?:

              dialog->resize(minimumSize()) does that work?

              Works for me if resized after show();

              J 1 Reply Last reply 20 Mar 2024, 19:30
              2
              • M mpergand
                20 Mar 2024, 19:24

                @JonB said in How can I programmatically make a dialog as small as possible?:

                dialog->resize(minimumSize()) does that work?

                Works for me if resized after show();

                J Offline
                J Offline
                jdent
                wrote on 20 Mar 2024, 19:30 last edited by
                #6

                @mpergand This works!! Thank you!!
                Also resize(1,1) also works!

                Great!

                1 Reply Last reply
                1
                • J jdent has marked this topic as solved on 20 Mar 2024, 19:31

                3/6

                20 Mar 2024, 19:06

                • Login

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