Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] Resize QDialog to fit all contents?

    General and Desktop
    5
    11
    26917
    Loading More Posts
    • 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.
    • CAD_coding
      CAD_coding last edited by

      Hi,
      I have a QDialog subclass in which there is a vertical layout.
      There are 3 widgets aligned vertically inside it.
      The middle widget is a QScrollArea to which I am setting a grid layout.
      The grid layout contains QTableView objects which I am creating by code using the Model/View framework.
      The number of QTableView in the grid layout is dynamic in the sense that user can change it through the UI.
      By default the grid layout contains only 1 QTableView & the size of the dialog is sufficient to fit all the contents.
      But when the user changes the number to 2 then the size of dialog is not changing to accommodate the 2 QTableView's.
      As a result the QTableView are creating horizontal scroll bars, which I don't want.
      I want the dialog to resize such that all the columns of all the QTableView's are always visible.
      How do I do this?

      1 Reply Last reply Reply Quote 0
      • CAD_coding
        CAD_coding last edited by

        This issue is really bugging me.
        Can I please have some guidance on this?

        1 Reply Last reply Reply Quote 0
        • CAD_coding
          CAD_coding last edited by

          It would really help me if somebody could answer this question?
          Am I unclear in my question?

          1 Reply Last reply Reply Quote 0
          • JKSH
            JKSH Moderators last edited by

            Hi,

            Calculate the "total width of all columns":http://qt-project.org/doc/qt-5.1/qtwidgets/qtableview.html#columnWidth, and then "resize your dialog":http://qt-project.org/doc/qt-5.1/qtwidgets/qwidget.html#size-prop accordingly.

            Similarly, resize your dialog when the number of views is changed.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply Reply Quote 0
            • CAD_coding
              CAD_coding last edited by

              Hi JKSH,
              Thanks for your reply.
              I think I totally missed that... ;)
              But I was hoping something like QDialog::resizeToContents();

              1 Reply Last reply Reply Quote 0
              • JKSH
                JKSH Moderators last edited by

                You're welcome :)

                resizeToContents() would create a circular dependency -- a child widget's size depends on its parent's size, so we can't make the parent's size depend on the child's size too.

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply Reply Quote 0
                • CAD_coding
                  CAD_coding last edited by

                  ohh...
                  Got it!

                  1 Reply Last reply Reply Quote 0
                  • P
                    poketmonister last edited by

                    very similar problem i have a QTableWidget instead of a QTableView

                    and resizing QTableWidget to rows and columns does not increase QDialog size, only increases QTableWidget size.

                    help me increase QDialog size also

                    plz help me

                    1 Reply Last reply Reply Quote 0
                    • M
                      Mar4eli last edited by

                      i can't now tell about qDialog, but there is "resizeToContents" with the help of the widget.

                      1. Create widget (for example: mainWidget);
                      2. specify widget layout;
                      3. add some additional widgets inside layout.
                      4. mainWidget."adjustSize()":http://qt-project.org/doc/qt-5/qwidget.html#adjustSize
                      5. Enjoy.

                      If it is necessary, i can post example code tomorrow.

                      1 Reply Last reply Reply Quote 0
                      • D
                        DBoosalis last edited by

                        This might work:

                        Create your own class that inherits QTableView. Now QTableView has a protected virtual method it inherits from QAbstractScrollArea called viewportEvent ( QEvent * event ). I think you can can a contents resize event of the viewport judging by the 4.8 docs. So once you get the size you can emit a signal to the dialog to resize itself.

                        In the resizing of the QDialog you may need to disconnect or set a flags in our QTableview so as not to get the circular calling: QTable::resize->QDialog::resize->QTable::resize

                        1 Reply Last reply Reply Quote 0
                        • P
                          poketmonister last edited by

                          hmmm....
                          Thanks for the reply, ill try it and post back

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post