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. resize parent widget to child widget width
Qt 6.11 is out! See what's new in the release blog

resize parent widget to child widget width

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 1.5k Views 1 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by user4592357
    #1

    i have a dialog which has a child widget table view.
    some of table items are long, so when the table view is updated due to insertion of the item in model, the table resizes, because i have set this:
    m_pTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);.

    but then my dialog (parent widget) doesn't resize itself so i get dialog with only part of the table widget visualized. i want to have the dialog also to be resized so i can have a complete view.

    what should i do?

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @user4592357 said in resize parent widget to child widget width:

      what should i do?

      Add a proper layout to your dialog. See also https://doc.qt.io/qt-5/layout.html

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      U 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @user4592357 said in resize parent widget to child widget width:

        what should i do?

        Add a proper layout to your dialog. See also https://doc.qt.io/qt-5/layout.html

        U Offline
        U Offline
        user4592357
        wrote on last edited by
        #3

        @Christian-Ehrlicher
        the table view and other items i dialog are inserted in layout

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @user4592357 said in resize parent widget to child widget width:

          the table view and other items i dialog are inserted in layout

          So what do you want to achieve? Automatically resize the whole dialog? This would irritate the user I would guess.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          U 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @user4592357 said in resize parent widget to child widget width:

            the table view and other items i dialog are inserted in layout

            So what do you want to achieve? Automatically resize the whole dialog? This would irritate the user I would guess.

            U Offline
            U Offline
            user4592357
            wrote on last edited by
            #5

            @Christian-Ehrlicher
            the dialog is initialized once, and user has to check items in it, so there's no more insertions after initialisation. so it'll be just one resize of the whole dialog.

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              So retrieve the viewport size and resize the dialog accordingly

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              U 1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                So retrieve the viewport size and resize the dialog accordingly

                U Offline
                U Offline
                user4592357
                wrote on last edited by
                #7

                @Christian-Ehrlicher
                okay. i have two columns actually, one is for text which can be long, and one is for icon, fixed size. and dialog has ability to filter from table rows. so when i type text of small item, only that small item is shown, and the first column resizes to width of that text. how can i always keep the width of first column the width of longest text in model?

                1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  See QHeaderView::setSectionResizeMode

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  U 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    See QHeaderView::setSectionResizeMode

                    U Offline
                    U Offline
                    user4592357
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher
                    i did this after init but the dialog is now too narrow:

                    	auto pViewport = m_pTableView->viewport();
                    	setFixedWidth(pViewport->width());
                    
                    1 Reply Last reply
                    0

                    • Login

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